Skip to content

Numbers, operators and variables in Zlv

How to write numbers, use operators and parentheses, name variables, pick values with when and otherwise, and read exact fractions in Zlv results.

Every Zlv line is an expression: numbers, operators, names and functions. This page covers the building blocks you will use on every sheet.

Numbers

Write numbers the normal way. You can group thousands with commas, and use a leading minus sign for negatives.

Live example
Edit the lines and press Run. Evaluated in your browser.

Evaluating…

Operators and order of operations

OperatorMeaningExample
+add10 + 5
-subtract10 - 5
*multiply10 * 5
/divide10 / 4
^power2 ^ 10
% or modremainder (modulo), between two numbers20 % 3, 17 mod 5 (desktop app)
( )group(10 + 5) * 2

Zlv follows the usual order of operations: powers first, then multiplication and division, then addition and subtraction. A number directly before parentheses multiplies, so 2(3 + 4) is 14.

Live example
Edit the lines and press Run. Evaluated in your browser.

Evaluating…

The desktop app also understands a few words as operators and ! as factorial:

Desktop example
Uses the native Rust engine: copy it into Zlv Desktop to see results.

Results appear next to each line in Zlv Desktop. Download it free.

Variables

Assign a value with = or :. The name goes on the left and can contain letters, digits and underscores, starting with a letter. Names cannot contain spaces: use monthly_rent, not monthly rent.

Live example
Edit the lines and press Run. Evaluated in your browser.

Evaluating…

A variable is available on every line below the one that defines it. If you assign the same name again later, lines below the new assignment use the new value.

Conditions with when and otherwise

Pick a value based on a comparison with when, and give a fallback with otherwise. Comparisons use <, <=, > and >=.

Live example
Edit the lines and press Run. Evaluated in your browser.

Evaluating…

Exact results in the desktop app

The desktop engine calculates exactly by default. Fractions stay fractions and constants stay symbolic, so 1/3 is shown as 1/3 and 2 * pi * 50 as 100π. Decimal inputs such as 37.5 are exact too and can appear as 75/2.

Desktop example
Uses the native Rust engine: copy it into Zlv Desktop to see results.

Results appear next to each line in Zlv Desktop. Download it free.

If you prefer decimals, turn off Exact Mathematics Mode in Settings > Calculation. Right-clicking a result also offers Copy Exact and Copy Decimal. See Settings, themes and languages.

All guides