0

I met a issue about number calculation in JavaScript, the scenario is listed as

below.

var number = 572.055
var result = Math.round(572.055*100)/100 

I would like to get result 572.06, but the result is 572.05, i try that alert(572.055*100), it alert the value 57205.4999999999,i don't know the reason. could you help to tell me how to avoid this issue? thanks a lot!

StudioTime
  • 18,874
  • 30
  • 103
  • 186
  • Related: [Round to at most 2 decimal places in JavaScript](https://stackoverflow.com/questions/11832914/round-to-at-most-2-decimal-places-in-javascript) – Ferrybig Feb 02 '16 at 08:56
  • This works fine https://jsfiddle.net/m6z8th0y/1/ – Julo0sS Feb 02 '16 at 08:56
  • I add '0.00001' to number,it don't impact the normal case and can also resolve the exception case. var result = Math.round((number+0.00001)*100)/100 . – Terry Y Chan Feb 02 '16 at 09:29

1 Answers1

-1

You could use Math.ceil() instead of Math.round.

Gopikrishnan
  • 179
  • 6