Difference between revisions of "Numbers and text"
Line 3: | Line 3: | ||
− | '''Converting number to text''': If you apply the | + | '''Converting number to text''': If you apply the [[Text_Concatenation_Operator%3A_%26|&]] operator or [[JoinText]]() to numbers, they convert the numbers to text values, using the number format specified for the variable or function in whose definition they appear. You can use this effect to convert (“coerce”) numbers into text values, for example: |
:<code>123456789 & '' → '123.5M'</code> | :<code>123456789 & '' → '123.5M'</code> | ||
:<code>123456789 & '' → '$123,456,789.00'</code> | :<code>123456789 & '' → '$123,456,789.00'</code> | ||
Line 12: | Line 12: | ||
You can also control the format used when converting numbers to text with the [[Text functions|NumberToText]] function. | You can also control the format used when converting numbers to text with the [[Text functions|NumberToText]] function. | ||
− | '''Converting text to number''': You can use the | + | '''Converting text to number''': You can use the [[Evaluate]]() function to convert a text representation of a number into an actual number, for example: |
:<code>Evaluate('12350') → 12.35K</code> | :<code>Evaluate('12350') → 12.35K</code> | ||
Evaluate() can convert any number format that Analytica can handle in an expression— and no others. Thus, it can handle decimals, exponent format, dates, <code>True</code> or <code>False</code>, a <code>$</code> at the start of a number (which it ignores), and letter suffixes, like <code>K</code> and <code>M</code>. | Evaluate() can convert any number format that Analytica can handle in an expression— and no others. Thus, it can handle decimals, exponent format, dates, <code>True</code> or <code>False</code>, a <code>$</code> at the start of a number (which it ignores), and letter suffixes, like <code>K</code> and <code>M</code>. | ||
− | An alternative method, for converting text to a number is to use the | + | An alternative method, for converting text to a number is to use the <code>Coerce Number</code> qualifier on a user-defined function. For example, you could define a user-defined function such as: |
:<code>ParseNum(X: Coerce Number) := X</code> | :<code>ParseNum(X: Coerce Number) := X</code> | ||
==See Also== | ==See Also== | ||
<footer>Math functions / {{PAGENAME}} / INF, NAN, and NULL - Exception values</footer> | <footer>Math functions / {{PAGENAME}} / INF, NAN, and NULL - Exception values</footer> |
Revision as of 22:24, 28 December 2015
Converting number to text: If you apply the & operator or JoinText() to numbers, they convert the numbers to text values, using the number format specified for the variable or function in whose definition they appear. You can use this effect to convert (“coerce”) numbers into text values, for example:
123456789 & → '123.5M'
123456789 & → '$123,456,789.00'
'The date is: ' & 38345 → The date is: Thursday, December 25, 2008'
You can also control the format used when converting numbers to text with the NumberToText function.
Converting text to number: You can use the Evaluate() function to convert a text representation of a number into an actual number, for example:
Evaluate('12350') → 12.35K
Evaluate() can convert any number format that Analytica can handle in an expression— and no others. Thus, it can handle decimals, exponent format, dates, True
or False
, a $
at the start of a number (which it ignores), and letter suffixes, like K
and M
.
An alternative method, for converting text to a number is to use the Coerce Number
qualifier on a user-defined function. For example, you could define a user-defined function such as:
ParseNum(X: Coerce Number) := X
Enable comment auto-refresher