Topic
Number Types
Every number in Rust has a type. The type tells Rust two things: how big the number can get, and whether it can go negative.
Quick Reference
ConceptWhat it means
i32A whole number, can be positive or negative
u64A whole number, always positive, used for lamports
u8A whole number from 0 to 255
f64A decimal number
asConverts a value from one number type to another
OverflowWhen a number is too big for its type, the program panics
TermWhat it meansWhen you use it
i32Signed 32-bit integer, can be positive or negativeDefault for whole numbers when sign matters
u64Unsigned 64-bit integer, always positive and very largeLamport amounts, token balances, timestamps in Solana
u8Unsigned 8-bit integer, 0 to 255 onlySmall counts, byte values
f6464-bit floating point, a decimal numberDefault for decimals (rarely used in Solana contracts)
asCasts a value from one number type to anotherWhen two variables have mismatched number types
Type inferenceRust guesses the type from the value you assignWhen you skip the type annotation, Rust picks i32 or f64
OverflowA number too big for its type, causes a panicWhen you hit it, switch to a larger type