The floating-point double
type can not exactly represent the value 1234567890123.4
and 1234567890123.3999
is the best it can represent and that is what the result is. Note that floating point types (e.g. IEEE-754) can not exactly represent all real numbers, hence these use approximations for most cases.
To be more precise, according to IEEE-754 double-precision floating point format 1234567890123.4
is represented as the hexadecimal value of 4271F71FB04CB666
, where in binary the sign bit is 0
, the 11 exponent and 52 singificand bits are 10000100111
and 0001111101110001111110110000010011001011011001100110
respectively. So this results in the value of (-1)sign×2exponent×(1.significand bits) = 1×240×1.1228329550462148311851251492043957114219 = 1234567890123.39990234375.
Note that not even a 128-bit floating point would store the value exactly. It would still result in 1234567890123.39999999999999999999991529670527456996609316774993203580379486083984375. Maybe you should instead attempt to use some fixed-point or rational number types instead.