Possible lossy conversion from double to float, given float values?

If I’m not mistaken, 0.5 are decimal numbers; thus, making it a float value.

You should not rely solely on your intuition when learning a new programming language.

In fact, 0.5 is a double literal. For a float literal you need to write 0.5f.

As The Java Language Specification (JLS 3.10.2) states:

A floating-point literal is of type float if it is suffixed with an ASCII letter F or f; otherwise its type is double and it can optionally be suffixed with an ASCII letter D or d.

See also:

Leave a Comment

tech