XGitHub

Leading Zeros

By default, Numora strips leading zeros from the integer part of a number. Set enableLeadingZeros: true to preserve them.

import { NumoraInput } from 'numora'

// Default - leading zeros removed
// "007" → "7", "0001" → "1"
const input = new NumoraInput(container, {
  enableLeadingZeros: false,
})

// Leading zeros preserved
// "007" → "007", "0001" → "0001"
const input = new NumoraInput(container, {
  enableLeadingZeros: true,
})

Rules

  • Only the integer part is affected - decimal zeros are never touched ("0.05" stays "0.05")
  • A bare "0" is always preserved
  • The sign is preserved for negative numbers ("-007""-7")

When to use each

  • Removed (default) - currency and general numeric inputs where leading zeros are meaningless
  • Preserved - product codes, IDs, or any format where zero-padding is significant

Auto-prepend leading zero

Set autoAddLeadingZero: true to automatically prepend 0before a bare decimal separator. Useful when you want .5 stored as0.5 so the value is unambiguously parseable downstream.

import { NumoraInput } from 'numora'

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

// Typing ".5"        → "0.5"
// Typing "-.5"       → "-0.5"  (requires enableNegative: true)
// Typing "."         → "0."
// Typing "1.5"       → "1.5"   (unchanged)
  • Runs as the last sanitization step, after enableLeadingZeros trimming - safe to combine
  • Respects decimalSeparator (e.g. "," for European format)
  • Off by default