parseNumber
parseNumber, function
def call parseNumber(source: text): number
def pure parseNumber(
source: text,
thousandSeparator: text,
decimalSeparator: text): number
def pure parseNumber(
source: text;
thousandSeparator: text,
decimalSeparator: text): number
Parses the text source into a number. The call overload auto-detects the
format from sample values; prefer the pure overloads with explicit separators.
source: the text to parse.thousandSeparator: the grouping separator.decimalSeparator: the decimal separator.
Example
table T = with
[| as Source, as Tho, as Dec |]
[| "1,234.5", ",", "." |]
[| "1 234,5", " ", "," |]
T.Value = parseNumber(T.Source, T.Tho, T.Dec)
show table "Parsed numbers" with
T.Source
T.Tho
T.Dec
T.Value
This outputs the following table:
| Source | Tho | Dec | Value |
|---|---|---|---|
| 1,234.5 | , | . | 1234.5 |
| 1 234,5 | , | 1234.5 |
Errors
Invalid values report an error; use tryParseNumber
to handle failures. Texts that would parse to NaN or Infinity are rejected
too.