Skip to content

Floats

Calibre uses float for decimal numbers.

let x : float = 3.14;
let y := 2.5;

You can also write an explicit float literal with the f suffix.

let x := 10f;
let y := 0.5f;

Floats are useful when you need fractions, measurements, or calculations that should not be rounded to whole numbers.

const bmi := fn (mass height : float) -> float => mass / height ** 2;

Like integers, floats can use e for powers of ten.

let small := 1.5e-2;
let large := 2e6f;

Float values work with the usual arithmetic operators.

const main = fn => {
let a := 7.5;
let b := 2f;
print(a + b);
print(a - b);
print(a * b);
print(a / b);
};

The standard library also provides helper functions on float, such as float.sqrt(9f), (3.5).round(), and float.sin(PI / 4f).