Skip to content

Decimals

Decimal options limit how many decimal digits a value can have and set the separator between the integer and decimal parts. decimalMaxLength defaults to 18 and decimalMinLength to 0.

decimalMinLength: 2

Padded when the field loses focus

Precision limits

import { NumoraInput } from 'numora'

// Cap at 2 decimal places. Numora refuses a third typed digit. It cuts extra digits
// off a pasted or app-set value without rounding, so "1.239" becomes "1.23"
const input1 = new NumoraInput(container, {
  decimalMaxLength: 2,
})

// Pad to at least 2 decimal places on blur and when your app sets the value, never
// while typing. The constructor throws if decimalMinLength is above decimalMaxLength
const input2 = new NumoraInput(container, {
  decimalMinLength: 2,
  // "1" on blur → "1.00"
})

Separators

import { NumoraInput } from 'numora'

// Comma decimal, dot thousands
const input = new NumoraInput(container, {
  decimalSeparator: ',',
  thousandSeparator: '.',
  // typing "1234,56" displays "1.234,56"
})

To detect separators from a locale, see Locale.

Typing and pasting a separator

  • Separator input. Typing , or . inserts the configured decimal separator. Numora blocks it if the value already has one.
  • Paste cleanup. Numora works out the format of pasted text from the text first. When both . and , appear, the last one is the decimal, so "1,234.56" becomes 1234.56. A mark that repeats is grouping, so "12.34.56" becomes 123456.
  • A single mark. When pasted text has one . or one ,, Numora reads it as grouping only if it could be grouping: one to three digits before it, exactly three after it, and no leading zero. In a default field a pasted 12,345 becomes 12345. A pasted 1,5, 1234,567 or 0,123 becomes 1.5, 1234.567 or 0.123. The field's own decimal separator is always the decimal: a pasted 1,234 is 1234 in a default field and 1.234 in a de-DE field.
  • No decimals. With decimalMaxLength: 0 Numora refuses a typed decimal separator, so typing 12.5 gives 125. A paste keeps the integer part: 12.75 becomes 12.
  • Invalid values. A negative or fractional limit, or decimalMinLength above decimalMaxLength, is an error. See invalid options.