Converting Numbers to Text

Revision as of 21:36, 26 January 2016 by Bbecane (talk | contribs)


To convert a number to a text value, you can use string concatenation, e.g., "" & x.

Examples

"" & (2^10) → '1024'
"" & Pi → '3.142'
"" & Exp(10) → '22.03K'

The coercion uses the number format for the object that contains the expression being evaluated. So, to use a different number format for the coercion, you must set the number format for that object.

To avoid confusion between the format for displaying results and the format used for number-to-text conversion, a better way to perform the conversion is to define a User-Defined Function for the specific number format you are interested in. For example:

Function NumberToYYYY_MMM_DD(x) := "" & x
{ Set its number format to Date → Custom → YYYY-MMM-DD }
Function NumberToDollars(x) := "" & x
{ Set its number format to Fixed Point, currency, two digits, show trailing zeroes }

With these, you can now accomplish the desired coercions using these functions. The number format for the function determines the conversion, rather than the number format for your variable.

See Also

Comments


You are not allowed to post comments.