Library reference

Round down

Choose the largest whole number at or below the input. This counts complete groups when a partly filled group does not count.

@floor

Simple example

Round 2.7 down.

Start2.7
Result2
lesson.zig
const std = @import("std");

pub fn main() !void {
    std.debug.print("{d}\n", .{@floor(@as(f64, 2.7))});
}
Output
2
Advertisements

Everyday examples

A roll holds enough ribbon for 4.8 bows. How many whole bows can you make?

Start4.8
Result4
lesson.zig
const std = @import("std");

pub fn main() !void {
    std.debug.print("{d}\n", .{@floor(@as(f64, 4.8))});
}
Output
4

A battery powered a clock for 3.9 hours. How many full hours passed?

Start3.9
Result3
lesson.zig
const std = @import("std");

pub fn main() !void {
    std.debug.print("{d}\n", .{@floor(@as(f64, 3.9))});
}
Output
3

A jug contains 6.2 cupfuls. How many full cups can you pour?

Start6.2
Result6
lesson.zig
const std = @import("std");

pub fn main() !void {
    std.debug.print("{d}\n", .{@floor(@as(f64, 6.2))});
}
Output
6
Run the example
Terminal
zig run lesson.zig
Official documentation