← All how-to recipes

How to add leading zeros to a number

✓ Verified in LibreOffice 25.8.7.3 ✓ Verified in Google Sheets (2026-08-30)

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

The formula

AppFormulaNotes
Excel (desktop)=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. We then ran the same formulas in Google Sheets, executed 2026-08-30: a formula-only workbook goes into Google Drive, which converts it to a Sheet and recalculates every formula with Google’s own engine, and comes back out as .xlsx carrying the values Google computed. It returned 00042 for the worked example, the same value LibreOffice produced. Both engines’ numbers on this page are executed results. The Excel formula follows Microsoft’s official documented syntax — we do not run desktop Excel.

Functions used

TEXT — see full Excel, Google Sheets & LibreOffice compatibility for each.

Related recipes

Related comparisons