Library reference

Round up

Choose the smallest whole number at or above the input. This helps when a partly filled group still needs its own container.

@ceil

Simple example

Round 2.3 up.

Start2.3
Result3
lesson.zig
const std = @import("std");

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

Everyday examples

A club needs 2.3 litres of paint. How many one-litre tins should it buy?

Start2.3
Result3
lesson.zig
const std = @import("std");

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

A bus journey uses 3.2 hours of parking. The car park charges by the hour started. How many hours count?

Start3.2
Result4
lesson.zig
const std = @import("std");

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

Each packet covers one shelf. A display needs 4.01 packets. How many full packets should the shop order?

Start4.01
Result5
lesson.zig
const std = @import("std");

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