Numbers and text


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'
Tip
The actual result depends on Number Format setting for the variable or function in whose definition the expression appears. The first example assumes the default Suffix format. The second assumes Fixed Point format, with currency and thousands separators checked, and two decimal digits. The third assumes the Long Date format. Use the Number format dialog on the Result menu to set the formats.

You can also control the format used when converting numbers to text with the NumberToText function, in which case the result does is not a function of the current number format setting.

NumberToText(123456789, 'Exponential') → '1.235e+008'

Converting text to number: Use the ParseNumber function to convert a text representation of a number into an actual number. For example,

ParseNumber('12350') → 12.35K

ParseNumber() can convert any number format that Analytica can handle in an expression— and no others. Thus, it can handle decimals, exponent format, True or False, a $ at the start of a number (which it ignores), and letter suffixes, like K and M, hex and binary. To parse dates and times, use the ParseDate function.

A second parameter to ParseNumber specifies the result when the text cannot be parsed as a number. To retain the unparsed original value in that case, use ParseNumber( x, x ).

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

See Also


Comments


You are not allowed to post comments.