Android Question Math accuracy problems

JLS

Member
Licensed User
Hi everybody:

As my very first Project, I'm creating a calculator.

I have found for example:

0.3 * 3 = 0.89999999999999

Why is this happening? How can it be fixed?

Thanks in advance
 

sorex

Expert
Licensed User
it's because the way how computers work with floating numbers.

you'll have to apply some rounding.
 
Upvote 0

klaus

Expert
Licensed User
In most cases BigNumber calculations are not necessaray, Double calculations are enough.
But the display is anoying, therefore the suggestion to use NumberFormat.
 
Upvote 0
Top