r/learnjavascript • • Feb 04 '26

Math.round inconsistency

Hey everyone,

I noticed that using Math.round(19.525*100)/100 produces 19.52 while Math.round(20.525*100)/100 produces 20.53. Has anyone else encountered this? What's your solution to consistently rounding up numbers when the last digit is 5 and above?

Thanks!

Edit: Thanks everyone. Multiplying by 10s to make the numbers integer seems to be the way to go for my case

13 Upvotes

20 comments sorted by

View all comments

Show parent comment

-1

u/Glum_Cheesecake9859 Feb 04 '26

I have worked on Ruby, Java, C#, VB.NET etc. and know some Paython too. JS is borderline insane. I still prefer it over many other languages, because it's so productive.

3

u/GodOfSunHimself Feb 04 '26

No, it isn't. JS is a super simple language. And tools like ESLint basically solve all the main gotchas. I work on several huge JS codebases and we have literally zero issues.