Difference between revisions of "Converting Numbers to Text"

(Number to Text)
Line 1: Line 1:
 
[[Category:Styles and options]]
 
[[Category:Styles and options]]
  
To convert a number to a text value, you can use [[Text Concatenation Operator: &|string concatenation]], e.g., <code>"" & x</code>.
+
To convert a number to a text value, you can use the [[NumberToText]] function or the [[Text Concatenation Operator: &|string concatenation]], e.g., <code>"" & x</code>.
 +
 
 +
To avoid confusion, using [[NumberToText]] is usually the better option. See [[NumberToText]] for information on that. The second method is described here.
  
 
==Examples==
 
==Examples==
Line 9: Line 11:
 
:<code>"" & Exp(10) &rarr; '22.03K'</code>
 
:<code>"" & Exp(10) &rarr; '22.03K'</code>
  
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.   
+
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.  When you set the number format while viewing a table for the variable, be sure that no cells are selected, because cell-level formats (formats that apply to only part of the table) do not influence the coercion to text.  
 
 
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:
 
 
 
:<code>Function NumberToYYYY_MMM_DD(x) := "" & x</code>
 
::<code>{ Set its number format to Date &rarr; Custom &rarr; YYYY-MMM-DD }</code>
 
 
 
:<code>Function NumberToDollars(x) := "" & x</code>
 
::<code>{ Set its number format to Fixed Point, currency, two digits, show trailing zeroes }</code>
 
 
 
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 ==
 
== See Also ==
  
 +
* [[Text Concatenation Operator: &|string concatenation]]
 
* [[Function_Parameter_Qualifiers#Coerce_.3Ctype.3E|Coerce function parameter qualifier]]
 
* [[Function_Parameter_Qualifiers#Coerce_.3Ctype.3E|Coerce function parameter qualifier]]
 
* [[Numbers]]
 
* [[Numbers]]

Revision as of 22:27, 19 March 2018


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

To avoid confusion, using NumberToText is usually the better option. See NumberToText for information on that. The second method is described here.

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. When you set the number format while viewing a table for the variable, be sure that no cells are selected, because cell-level formats (formats that apply to only part of the table) do not influence the coercion to text.

See Also

Comments


You are not allowed to post comments.