I know the problem of doubles due to base 2 calculations:
var total: Double = 0.1
total *= 0.1
total /= 0.1
println(total) // 0.10000000000000002
I understand that BigDecimal should be used for money related calculations, but in my case the little precision loss is acceptable, cuase all the currency calculation I need to do is convert currency C1 to currency C2 and back to currency C1. The only thing is that the two values of C1 after this conversion should match, when I show the result to customer with 5 decimal precision.
Now I'm trying to figure out, how much the value might drift over this conversion at worst case scenario? What are the numbers that might cause the worst case scenario?
You could read the description of double-precision floating-point:
Since you want 5 fraction digits, that means you're ok up to max. 10 integral digits.
Or you could test it. Sometimes empirical evidence is more convincing:
Output
Yup, 10 is good, 11 bad.