number, numberl

number, numberl — attempt to convert an expression to a number.

Synopsis

number (s_exp)
numberl (s_exp)

		

Arguments

s_exp

Any Gamma or Lisp expression.

Returns

A numeric representation of the s_exp if possible, otherwise zero.

Description

This function attempts to convert its argument to a number. Integer and floating point values remain untouched. String arguments are converted to numbers by attempting to read a number from the string starting at the first character in the string. The longest legal number at the beginning of the string is used. All other data types return zero. If possible, the result will be an integer. If the result cannot be represented as an integer, a real (floating point) number is returned.

The number function will convert a string in local-invariant format to a number. For example, the string "1.2" will convert to the number 1.2. In locales where the decimal separator is not a dot, number will also attempt to perform the conversion in the current locale.

The numberl function (with an l for locale) will strictly perform the conversion in the current locale. For example, in a locale that uses comma as a decimal separator, number("1.2") will produce 1.2, numberl("1,2") will produce 1.2, and numberl("1.2") will produce 1.

Example

Gamma> number(5);
5
Gamma> number("5.4m");
5.4000000000000003553
Gamma> number("m5.4");
0
Gamma> number(#a);
0
Gamma>