From the course: First Look: Rust

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Scalar data types: Floats

Scalar data types: Floats - Rust Tutorial

From the course: First Look: Rust

Start my 1-month free trial

Scalar data types: Floats

- Rust also has two primitive types for floating point numbers, which are numbers with decimal points. Rust floating point types are f32 and f64 which are 32 bits and 64 bits in size, respectively. If you see the variable here, x has the value 2.0, which by default, the Rust allocates 64 bits of space and it's a floating point. If you need to explicitly annotate the type to be 32 bits, we can do as in the variable y. Add a colon, followed by f32, and then assign it to whatever value you need. As in most other programming languages, a boolean type in Rust has two possible values: true and false. The boolean type in Rust is specified using the keyword bool. Typically, these types are used whenever flags need to be set, and based on the value of the flag, allow the program to perform a certain operation. So, if we want to set the value of t to be true, we just write true, which is a keyword here. And true in other programming languages you would know this as one. And if we want to…

Contents