Skip to content
Justice Tech School

Numbers and Math

Operators + - * / %. Integer division drops the fraction. Float methods: sqrt, powi, powf, abs, floor, ceil, round and min and max. std::f64::consts::PI holds pi.

Example
println!("{} {} {}", 17 / 5, 17 % 5, 17.0 / 5.0);
let x: f64 = 81.0;
println!("{} {} {}", x.sqrt(), 2f64.powi(10), (3.7f64).round());
println!("{:.4}", std::f64::consts::PI);

Result

3 2 3.4
9 1024 4
3.1416

Exercise

Square root.

x.()

Quiz Test

What is 17 / 5 with integers?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.