-5

java. i have known "A float is generally subject to round-offs in its 8th significant digit",and using double will avoid that problem.

can anyone tell me why it will round-offs in its 8th significant digit.

star zhang
  • 1
  • 1
  • 4

1 Answers1

0

In Java, the base of floating-point arithmetic is binary, not decimal. Numbers are not rounded using decimal digits. They are rounded using binary digits.

The spacing of binary fractions is irregular relative to decimal fractions, so the rounding effects will be different at different powers of ten.

Eric Postpischil
  • 195,579
  • 13
  • 168
  • 312