Converts a string to a number.
Syntax
@TextToNumber(value:string)
: double
Parameter |
Description |
value |
A string that represents a number in integer,
decimal, or scientific format. Cannot be an expression. |
Return value |
Description |
Date |
The equivalent number, or 0 if the string cannot
be converted. |
Examples
This example demonstrates the conversion
of various strings to numbers.
function p(stuff) {
print("<<<" + stuff + ">>>");
}
var n = "12";
p("text is 12, n is " + @TextToNumber(n)); // <<<text is 12, n is 12>>>
var n = "1.2";
p("text is 1.2, n is " + @TextToNumber(n)); // <<<text is 1.2, n is 1.2>>>
var n = "1.2e-4";
p("text is 1.2e-4, n is " + @TextToNumber(n)); // <<<text is 1.2e-4, n is 0.00012>>>
var n = "5 * 4.1";
p("text is 5 * 4.1, n is " + @TextToNumber(n)); // <<<text is 5 * 4.1, n is 0>>>
var n = "foo";
p("text is foo, n is " + @TextToNumber(n)); // <<<text is foo, n is 0>>>