Skip to content

Leading zeros

By default, Numora removes leading zeros from the integer part of a number. Set allowLeadingZeros: true to keep them.

allowLeadingZeros: true

Leading zeros are kept

import { NumoraInput } from 'numora'

// Default: leading zeros removed
// "007" → "7", "0001" → "1"
const input1 = new NumoraInput(container)

// Leading zeros kept
// "007" → "007", "0001" → raw "0001" (shown as "0,001" with the default grouping)
const input2 = new NumoraInput(container, {
  allowLeadingZeros: true,
})

Rules

  • Only the integer part is affected. Decimal zeros are never touched ("0.05" stays "0.05").
  • Numora always keeps a bare "0"
  • Negative numbers keep their sign ("-007" → "-7", with allowNegative: true)

Keep the default for currency and numeric inputs. Enable leading zeros for product codes, IDs and other formats where zero-padding matters.

Auto-prepend leading zero

Set padLeadingZero: true to prepend 0 before a bare decimal separator. Use it when you want .5 stored as 0.5, so the value parses the same way everywhere downstream.

import { NumoraInput } from 'numora'

const input = new NumoraInput(container, {
  padLeadingZero: true,
})

// Typing ".5"        → "0.5"
// Typing "-.5"       → "-0.5"  (requires allowNegative: true)
// Typing "."         → "0."
// Typing "1.5"       → "1.5"   (unchanged)
  • Runs after allowLeadingZeros trimming, so you can combine the two. Only the optional maxLength truncation runs later.
  • Uses your decimalSeparator (e.g. "," for European format)