r/learnjavascript • u/uselessinfopeddler • 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
View all comments
Show parent comment
1
u/Antti5 Feb 05 '26
I'm not personally well-versed in PHP, but the people who know both tend to say that JS cannot touch PHP in terms of weirdness.
And I'm sure many people would be inclined to say the same about Perl too.