Wednesday, 15 September 2010

java - Float precision with specific numbers -



java - Float precision with specific numbers -

the next value gives me wrong precision. observed specific numbers. might floating representation problem, wanted know specific reason.

string m = "154572.49"; //"154,572.49"; float f = float.parsefloat(m); system.out.println(f);

the output printing 154572.48 instead of 154572.49.

if want decimal numbers come out entered them in java, utilize bigdecimal instead of float.

floating point numbers inherently inaccurate decimals because many numbers terminate in decimal (e.g. 0.1) recurring numbers in binary , floating point numbers stored binary representation.

java floating-point floating-accuracy

No comments:

Post a Comment