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.

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.

See also

User Contributed Notes
0 notes + add a note