Skip to content

Integers & Floats

int and float are the two core numeric types. Integer division promotes to float; the reverse needs an explicit call via std::math. Float literals accept scientific notation (1.5e3):

Decimal literals, the arithmetic operators, and int → float coercion.

02-numbers-int-float.zolo
Playground
// Feature: Numbers — `int` and `float`

// Syntax: decimal literals; `.` introduces a float

// When to use: arithmetic. The Lua VM treats every number as a

// double internally; `int` is an informational annotation that

// affects inference and implicit conversions in typed contexts.


use std::math

// Integers — no decimal point.

let a: int = 42
let b: int = -17

// Floats — with a dot OR scientific notation.

let c: float = 3.14
let d: float = 1.5e3  // 1500.0

let e: float = 2.5e-2  // 0.025


// Operations: + - * / % ** (power)

print(a + b)  // 25

print(c * 2.0)  // 6.28

print(a / 5)  // 8.4 (division promotes to float)

print(a % 5)  // 2

print(2 ** 10)  // 1024


// Coercion: int → float is implicit; float → int requires a call.

let f = a + c  // f: float = 45.14

print(f)

// Explicit conversion via stdlib.

let g = math.floor(3.9)  // 3

let h = math.round(3.5)  // 4

print(g, h)

See also

enespt-br