PARSE_NUMBER

The function PARSE_NUMBER converts a string containing numeric digits into a number.

This function accepts a String and parses any numeric digits into a Number. If a Number cannot be parsed from the String, then zero is returned. Any non-numeric characters in the String are ignored.

Declaration

PARSE_NUMBER(string_containing_a_number) -> parsed_number

Parameters

string_containing_a_number (required, type: string) The string to parse the number from.

Return Values

parsed_number (type: number) The resulting number.

Examples

Although capable of much more, when given a string that contains a number, PARSE_NUMBER will return the number.

PARSE_NUMBER("299792458") -> 299792458

The PARSE_NUMBER function will ignore additional characters between numbers such as thousandths

PARSE_NUMBER("299,792,458") -> 299792458

The PARSE_NUMBER function will interpret a period character ('.') as separating the decimal portion of the number.

PARSE_NUMBER("3.141592653589793") -> 3.141592653589793

We saw earlier that the PARSE_NUMBER function will ignore thousandths separators, it will in fact, ignore any non-numeric character.

PARSE_NUMBER("299hello792458") -> 299792458

When PARSE_NUMBER is given a string that does not contain a number, it returns zero.

PARSE_NUMBER("not a number") -> 0

When encountering a numeric character that can no longer be a part of a number, PARSE_NUMBER will omit any digits from the rest of the String.

PARSE_NUMBER("1.1.0") -> 1.1

This allows parsing numbers that may include additional text, for example, the period at the end of the first sentence stops the number parsing in this example.

PARSE_NUMBER("This is a number 1.1. 5 is another number.") -> 1.1

Discussion

Unlike other parsing functions, while the PARSE_NUMBER function is spiritually the opposite of the FORMAT_NUMBER function, this relation is not exact. For example, the PARSE_NUMBER function cannot parse exponential notation that the FORMAT_NUMBER function generates.

PARSE_NUMBER("1e-2") -> 1

Another difference is that the PARSE_NUMBER function is locale un-aware. If a number has been formatted with a European locale that uses periods for thousandths groupings, and commas to separate the decimal, the PARSE_NUMBER will return an incorrectly interpret the first period as a decimal separator.

PARSE_NUMBER("299.792.458") -> 299.792

Last updated