I just started to develop in java at my company and ran into a rounding problem that i can't solve as i like.
Got this number, 69,1999999999998 i want to round so i get 69,20.
But the result end up 69.2. I want my number to keep the zero.
My code looks like this
var number: int = 69,1999999999998
number = Math.round(100000 * number) / 100000;
//number = 69.2
Does anyone know what i should do?
FYI, i'm calculating amounts on articles and want to keep the correct decimal value for the currency denomination.
How are you displaying the number? The printf() method has formatting controls that will give you what you want.
You understand of course that computers don't represent floating point numbers with exact precision (with exceptions of course), that what you're seeing isn't an error but is inherent in any programming language that uses floating points. If accuracy is of paramount importance, such as when dealing with financial numbers, then don't use doubles but instead use BigDecimals. More often though the accuracy of double is adequast and what is more important is probably how you display the results (which is what Norm was getting at above).
We are using "Alert" to popup the message.
What class/mehtod is Alert ?
Originally Posted by Nicke