Number string

Purpose: Convert number to string.

 number-string <number> [ to <string> ] \
     [ base <base> ] \
     [ status <status> ]

<number> is converted to <string> in "to" clause, using <base> in "base" clause, where <base> is by default 10. <base> can be between 2 and 36, inclusive. <number> can be positive or negative (i.e. signed) and can be of any integer type up to 64-bit (char, int, long, long long etc.).  If "to" clause is omitted, then <number> is printed out.

Note that any letters in <string> (depending on the <base>) are always lower-case.

If there is an error, such as if <base> is incorrect, then <status> number (in "status" clause) is GG_ERR_FAILED, otherwise it's GG_OKAY.

If number-string prints out a number (i.e. "to" clause is omitted), and this is within write-string, then <number> is output into the buffer that builds a new string.
Shortcut
For convenience, you can use a shortcut for converting a string to a number, by prepending a "$" sign to the variable name, for example:
 set-number n = -10
 set-string s = "This is number " + $n

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

Effectively, $ in front of a number variable is the same as number-string that converts it to a string with the base of 10. If a string cannot be converted to a number, your program will error out. To check values with a status, or to use different bases, use number-string.

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

In this case number "s" will have value of "This is number 5", because numbers -10 and 15 are added to produce 5, 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 "801":
 set-number x = 801
 number-string x to res

The following will store "-238f" to string "res":
 set-number x = -9103
 number-string x to res base 16

To print out a number -131:
 set-number x = -131
 number-string x



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