Friday, August 22, 2003

Don't use floats for money fields

On my current project we are getting slammed by rounding errors from using floats. look at this code:

double x = 426.39 + 834.20;
System.out.println("x: " + x);

Surprisingly it prints:
x: 1260.5900000000001