Float
| Description: | Numbers with some fractional component |
| Annotation: | float |
| Literal syntax: | A decimal numeric value including a decimal place. E.g., 1.5, 2.0, -15.333 |
| Casts: | into float |
| See also: | Types of Data - Floats |
Additional language notes
Floats are internally represented as IEEE-754 floats with 64 bit precision.
Scientific notation is supported in literals, e.g.
1e3or1.5e-3.A float is always displayed with a decimal point, even when it has no fractional part. The
/operator always returns a float, even when both operands are integers (use//for integer division).Floats and integers can be compared with each other.
10 / 2 # => 5.0 1e3 # => 1000.0 0.1 + 0.2 # => 0.30000000000000004 2.0 == 2 # => trueinto inttruncates the fractional part. Usemath round,math floorormath ceilto round instead.