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
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.
The PARSE_NUMBER function will ignore additional characters between numbers such as thousandths
The PARSE_NUMBER function will interpret a period character ('.') as separating the decimal portion of the number.
We saw earlier that the PARSE_NUMBER function will ignore thousandths separators, it will in fact, ignore any non-numeric character.
When PARSE_NUMBER is given a string that does not contain a number, it returns zero.
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.
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.
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.
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.
Last updated