floats and doubles

When you’re doing *really* precise maths with large numbers (for that you can read currency conversions), Java floats do not necessarily do what you might expect. I’ve just wasted half a day tracking down a rounding error for a calculation that was 3 cents out for numbers over 7 million. It’s a small triumph but one I’ll take gladly at the moment. In the end I just switched to use doubles instead and they work as I’d expect (which I guess may not actually be correct but they do at least match Excel and my calculator!).

Share