Possible Duplicate:
Why can't decimal numbers be represented exactly in binary?
i get very odd behaviour from simple float maths. eg.
//create a float with value of 1.0
float f = 1.0;
//take 0.1 from its value
f -=0.1;
for the first few times when i minus 0.1 it returns 0.9, 0.8, 0.7...... then for some reason it will return 0.699999999999, 0.59999999999 and so on. to say this is unexpected is an understatement.
so to fix this i either need to know why it would do this or a math function similar to Round(float) where it will round the number from 0.5999999 to 0.6.
thank you
edit, ok sorry for asking lol any fix available? like Round(float) kinda thing?
other edit: for the next person to ask about this heres a fix
final DecimalFormat myFormat = new DecimalFormat("#.#");
myFormat.format(myFloatValue)
this will change myFloatValue 0.599999 into 0.6