0

Can be Java float point numbers literal represent in octonary? I've read the Java document said:

A floating-point literal may be expressed in decimal (base 10) or hexadecimal (base 16).

When I try this in the IDE:

double d = 0b1.1D;

The code was highlighted as an error. but when trying:

double d = 011.0;            // ??

did not get any errors, and the output value equals to 11.0, not 9 as expected.

Does the '0' prefix just being ignored? Appreciate any one can help.

1 Answers1

1

If you're referring to octal, Java does not support floating point values represented in base-8. However, you could use Double#doubleToLongBits to extract the mantissa and exponent of the floating point value and convert them to an equivalent octal value.

Jacob G.
  • 28,856
  • 5
  • 62
  • 116