Browse the docs

parseNumber

Reads a number out of text with currency, thousands separators, percent or k/M/B.

Details #

parseNumber(text, locale?) takes one or two arguments and returns a number.

  • Currency symbols and codes, and spaces, are ignored: $1,234.50, EUR 99.

  • Grouping and decimal marks follow locale (de_DE, fr), or this Mac's region when it is left out. If that doesn't fit, 1,234.50 style is tried.

  • Negatives can be -5, −5 or accounting style (1,234.50).

  • 12% is 0.12.

  • A trailing k (thousand), M (million) or B (billion) multiplies: 1.2k is 1200.

Parameters #

Takes 1 to 2 arguments. {{ parseNumber(text, b?) }}

Examples #

parseNumber("$1,234.50")
→ 1234.5
parseNumber("1.234,50", "de_DE")
→ 1234.5
parseNumber("(12)")
→ -12

Gotchas #

  • Text with no number is an error: parseNumber() couldn't find a number in 'abc'.

  • Both M and m mean million here.