Double string

Purpose: Convert double to string.

double-string <double> [ to <string> ] \
    [ width <width> ] \
    [ precision <precision> ] \
    [ format-floating | format-scientific | format-compact ]

<double> is converted to <string> in "to" clause, using <width> and <precision> (in "width" and "precision" clauses) and using one of the formats ("format-floating", "format-scientific" or "format-compact"). By default "format-floating" is used with the <precision> of 6. "format-scientific" will output in the format that uses the exponent with a single digit before the decimal point. "format-compact" will choose the shorter of the two. <double> can be positive or negative (i.e. signed) and is a 64-bit double-precision floating point value.  If "to" clause is omitted, then <double> is printed out.

If double-string prints out a double (i.e. "to" clause is omitted), and this is within write-string, then <double> is output into the buffer that builds a new string.

Note that if there's an overflow the result is "inf" or "-inf" for positive and negative infinity.
Shortcut
For convenience, you can use a shortcut for converting a double to a string, by prepending "$$" to the variable name, for example:
set-double n = -10.41
set-string s = "This is double " + $$n

The above is the same as:
set-double n = -10.41
double-string n to sval
set-string s = "This is double " + sval

Effectively, $$ in front of a double variable is the same as double-string that converts it to a string with all the default options.

You can use $$ for an expression, in which case the expression must be within parenthesis:
set-double n1 = -10.41
set-double n2 = 15.13
set-string s = "This is double " + $$(n1+n2)

In this case double "s" will have value of "This is double 4.72", because doubles -10.41 and 15.13 are added to produce 4.72, which is then converted to a string and finally added to the first string.
Examples
The following will allocate memory for string "x" to be "    8.8422000000e+02":
double-string 884.22 width 20 to str precision 10 format-scientific to x

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.