published: 5th of February 2022
Integers represent whole numbers. Rust has both unsigned integers and signed integers. unsigned integers cannot be negative, and have a higher positive range than signed integers, that can be negative, but have a lower postive range.
The following table lists the integer literal types in Rust.
The following table lists the formats that are supported for an integer literal definition.
|Byte (u8 only)||b'Z'|
// i32 by default let the_answser = 42; // Annotate the type of integer let dinner_for_two: i8 = 69; // Integer suffixing is also supported for type annotation let its_friday = 420u16; // => 420 // Underscores can help to improve readbility let you_da_winnah = 1_16_32_5_12_19_40_i64; // => 116325121940
Floating points represent a number with a fractional component expressed in IEEE-754 format. Rust has two floating point types: f32 and f64 .
The following table list the floating point literal types and their bits of precision.
// f64 by default let highly_sexual = 420.69; // Annotate the type of float let dinner_for_two: f32 = 69.69; // Float suffixing is also supported for type annotation let its_friday = 420.69f32; // => 420.69 // Underscores can help to improve readbility let you_da_winnah = 420_69.1337_f64; // => 42069.1337