Data types
Use whole numbers for things you count. Use a decimal when you need part of a unit.
Simple example
Divide five into two equal parts.
Start5 ÷ 2
Result2.5
const std = @import("std");
pub fn main() !void {
const value: f64 = 5.0;
std.debug.print("{d}\n", .{value / 2.0});
}
2.5
Advertisements
Everyday examples
Two friends share a length of ribbon equally. How many metres does each friend get?
Start7 m ÷ 2
Result3.5
const std = @import("std");
pub fn main() !void {
const metres: f64 = 7.0;
std.debug.print("{d}\n", .{metres / 2.0});
}
3.5