Math: Rounding
● Beginner2 min
floor rounds down, ceil rounds up, round rounds to the nearest, halves away from zero.
use std.math
fn main() {
print(math.floor(2.7))
print(math.ceil(2.1))
print(math.round(2.5))
print(math.round(-2.5))
print(Int(2.7))
}The program ran and printed:
kavach run rounding.kav
2.03.03.0-3.02
They give a Float back. Int(2.7) turns a float into a whole number by cutting the fraction off.