From the course: Rust Essential Training

Unlock the full course today

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

Floating-point data types

Floating-point data types - Rust Tutorial

From the course: Rust Essential Training

Start my 1-month free trial

Floating-point data types

- The integer data types are not intended to store fractional values. If you need to store a number with decimal places, you should use a floating-point type. Rust supports two floating point data types. A 32 bit version, and a 64 bit version. You may hear these referred to as single precision and double precision respectively. Floating-point values in rust are stored in several parts including a fractional value and an exponential value that's used to scale it. The largest possible 64 bit floating-point value is 1.7 times 10 to the power of 308. So that exponent allows us to represent a huge range up to some really, really big numbers. However, even though that number is huge in magnitude, the fractional component has a finite amount of precision. So we're limited in the number of significant digits or decimal places we can represent. As an example, let's consider how PI would be stored as a floating point value. PI is an…

Contents