Skip to content

Float

A Float is a 64-bit binary floating-point number, written with the suffix f: 0.5f, 6.02e23f, 2f. A number with a decimal point and no suffix is a Decimal. Arithmetic on two Float operands gives a Float:

7.0f / 2.0f
3.5

A binary fraction cannot hold most decimal fractions exactly, so a sum can be a little off:

0.1f + 0.2f
0.30000000000000004

That is why a Float is the wrong type for money; a Decimal holds an amount exactly as it is written.

An Int and a Float do not mix: 1 + 2.0f is refused, and so is a Decimal beside a Float. float and int convert, the second truncating:

[1.float() + 2.0f, 3.9f.int().float()]
[3.0, 3.0]