Question

I want to round to two decimal points so naturally I'd use:

Double number = Math.round(number*100.0)/100.0 

But I ended up getting really long outputs, with lots of decimal points. So I tried different inputs for Math.round() similar to the ones I need to use and found that

Math.round(8.3391700279483738E17) = 833917002794837376
Math.round(8.3391700279483738E17 * 100) / 100.0 = 9.223372036854776E16

Does this make sense to anyone?

Was it helpful?

Solution

Your code seems to be correct

Math.round(8.3391700279483738E17) = 833917002794837376

makes sense as 8.3391700279483738E17 mathematically means 8.3391700279483738 * 10^17 or

8339170027948373800 and not a decimal number. The small marginal difference is due to Delta error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top