Skip to content

Scientific notation

Numora expands values like 1.5e-7 to decimal notation. It usually enters the field through paste or through values your app passes in. A lone e typed at the end of the field is ignored, but an e typed between digits completes a token and expands too (1e5 becomes 100000). Expansion uses string arithmetic, so no floating-point precision is lost.

1.23 × 10⁻⁴

Expanded to decimal notation

To refuse scientific notation instead, set allowScientificNotation: false (default true). Numora then rejects a paste that holds a complete exponent, such as 1.5e-7, and an e typed between two digits. The field keeps the value it had. Values your app passes in (defaultValue, setValue()) are expanded either way, because String(1e21) is "1e+21" in JavaScript.

import { NumoraInput } from 'numora'

const input = new NumoraInput(container)

// Paste any of these and Numora expands it. The raw value becomes:
// "1.5e-7"   → "0.00000015"
// "2e+5"     → "200000"  (shown as "200,000" with the default grouping)
// "1.23e-4"  → "0.000123"
// "5e3"      → "5000"    (shown as "5,000")
// "-1.5e-7"  → "-0.00000015"  (with allowNegative: true)
// "1.5e-17"  → "0.000000000000000015"  (18 decimals, no precision lost)
// Digits past decimalMaxLength (18 by default) are cut off after expansion:
// "1.5e-19" → "0.000000000000000000"

Both e and E work.

Limits

  • The exponent can be at most 1000 in either direction. 1e1000 expands to a 1 and 1000 zeros. 1e1001 and 1e-1001 are dropped, and the field ends up empty.
  • The exponent must be a whole number. 1e3.5 is dropped. An e with no digits after it is removed and the number stays: 1e becomes 1.
  • Typing 1, e, 5 in that order gives 15, because the e at the end of the field is ignored.