Float¶
A Float is a 64-bit binary floating-point number. Use it for measurements
and scientific values, where a very small rounding error does not matter. A
Float is 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
This is why a Float is the wrong type for money. A Decimal holds an
amount exactly as it is written.
A Float does not mix with an Int or a Decimal: 1 + 2.0f is a type
error. float and int convert between Int and Float, and int drops
the fraction:
[1.float() + 2.0f, 3.9f.int().float()]
[3.0, 3.0]