← All how-to recipes

How to add leading zeros to a number

✓ Verified in LibreOffice 25.8.7.3

Pad a number to a fixed width with zeros in front (e.g. for IDs or ZIP codes).

The formula

AppFormulaNotes
Excel=TEXT(A2,"00000")TEXT with a zero-pattern pads to that many digits; result is text.
Google Sheets=TEXT(A2,"00000")Identical.
LibreOffice Calc=TEXT(A2,"00000")Identical.

How it works

TEXT(value, "00000") formats the number with at least five digits, adding zeros on the left. 42 becomes '00042'. The result is text, so use it for display/export rather than further math.

Verified, not just documented

We ran =TEXT(A2,"00000") in LibreOffice 25.8.7.3 (headless, with forced recalculation) and it returned 00042 — exactly the expected result. Every formula here is confirmed by actually executing it.