Difference between revisions of "Converting Numbers to Text"

(Number to Text)
m
 
Line 1: Line 1:
 
[[Category:Styles and options]]
 
[[Category:Styles and options]]
  
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>.
+
There are two ways to convert a number or date to a text value: One is to use the [[NumberToText]] function. It lets you specify the format explicitly as a parameter.  See [[NumberToText]] for details. The other, described here, uses the [[Text Concatenation Operator: &]] to concatenate the number with a text --- 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 11: Line 9:
 
:<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.  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.  
+
Text concatenation automatically converts ("coerces) any number to text. It uses the [[Number format]] set for the variable whose definition contains the expression.  So, the result may vary depending on the Number format specified. 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 you select the whole table, not just selected cells -- because cell-level formats don't affect the coercion to text.  
  
 
== See Also ==
 
== See Also ==

Latest revision as of 23:26, 18 July 2018


There are two ways to convert a number or date to a text value: One is to use the NumberToText function. It lets you specify the format explicitly as a parameter. See NumberToText for details. The other, described here, uses the Text Concatenation Operator: & to concatenate the number with a text --- e.g., "" & x.

Examples

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

Text concatenation automatically converts ("coerces) any number to text. It uses the Number format set for the variable whose definition contains the expression. So, the result may vary depending on the Number format specified. 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 you select the whole table, not just selected cells -- because cell-level formats don't affect the coercion to text.

See Also

Comments


You are not allowed to post comments.