String double

Purpose: Convert string to double.

string-double <string> [ to <double> ] \
    [ status <status> ]

<string> is converted to <double> in "to" clause.

<status> double (in "status" clause) is GG_OKAY if conversion was successful. If it wasn't successful, <double> is 0.0 and <status> is GG_ERR_OVERFLOW if <string> represents a double that requires over 64 bits of storage, GG_ERR_INVALID if cannot convert, GG_ERR_EXIST if <string> is empty or no digits specified. If there are trailing invalid characters (for instance "182.33xy"), <double> is the result of conversion up to the first invalid character and <status> is GG_ERR_TOO_MANY. In this example, <double> would be 182.33.
Shortcut
For convenience, you can use a shortcut for converting a string to a double, by prepending "##" to the variable name, for example:
set-string s = "-10.31"
set-double n = ##s + 10

The above is the same as:
set-string s = "-10.31"
string-double s to val
set-double n = val + 10

Effectively, ## in front of a string variable is the same as string-double that converts it to a double. If a string cannot be converted to a double, your program will error out. To check values with a status, use string-double.

You can use ## for an expression, in which case the expression must be within parenthesis:
set-string s1 = "-10.31"
set-string s2 = "2"
set-double n = ##(s1+s2) + 10

In this case double "n" will have value of -0.312, because strings "s1" and "s2" concatenate to produce "-10.312", which is then converted to a double and finally 10 added to it, producing -0.312.
Examples
In this example, double "n" would be 49.11 and status "st" would be GG_OKAY:
string-double "49.11" to n status st

See also
Doubles
abs-double  
double-expressions  
double-string  
mixing-doubles-and-numbers  
set-double  
string-double  
Strings
copy-string  
count-substring  
delete-string  
double-string  
lower-string  
match-regex  
new-string  
number-string  
read-split  
replace-string  
scan-string  
set-string  
split-string  
string-double  
string-expressions  
string-length  
string-number  
trim-string  
upper-string  
write-string  
See all
documentation


Copyright (c) 2019-2025 Gliim LLC. All contents on this web site is "AS IS" without warranties or guarantees of any kind.