Let's begin exploring how Rust handles information that's not a string or a whole number.
Numbers can also have decimal points, like 3.14
or 9.99
. In programming, these are treated differently from integers.
Engagement Message
Have you worked with decimals before?
Numbers with a decimal point are called floating-point numbers, or simply floats. In Rust code, the common types are f32
and f64
(for 32-bit and 64-bit precision).
Examples include 1.0
, 3.14159
, or -2.5
.
Engagement Message
Do you think the value 100
stored without quotes would be a float?
You can store floating-point numbers in variables just like other types:
You can also perform standard math operations (+
, -
, *
, /
) with floats.
