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.50style is tried.Negatives can be
-5,−5or accounting style(1,234.50).12%is0.12.A trailing
k(thousand),M(million) orB(billion) multiplies:1.2kis1200.
Parameters #
Takes 1 to 2 arguments.
{{ parseNumber(text, b?) }}
Examples #
parseNumber("$1,234.50")→
1234.5parseNumber("1.234,50", "de_DE")→
1234.5parseNumber("(12)")→
-12Gotchas #
Text with no number is an error:
parseNumber() couldn't find a number in 'abc'.Both
Mandmmean million here.