Jeb Jeb - 1 year ago 57
Java Question

How can a primitive float value be -0.0? What does that mean?

How come a primitive float value can be -0.0? What does that mean?

Can I cancel that feature?

When I have:

float fl;

fl == -0.0
and so does
fl == 0
. But when I print it, it prints

Answer Source

Because Java uses the IEEE Standard for Floating-Point Arithmetic (IEEE 754) which defines -0.0 and when it should be used.

You can get around the problem by adding 0.0


Double.toString(value + 0.0);

See: Java Floating-Point Number Intricacies

Operations Involving Negative Zero
(-0.0) + 0.0 -> 0.0

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download