ParseNumber
ParseNumber(x, badVal, decimal)
It converts text «x» to a numeric value, if it has a number format (including dates or time) that is valid in Analytica. If not, e.g. ParseNumber("hello")
, it returns Null, or «badVal» if specified. If «x» is already a number, it just returns the value «x».
If «x» uses a comma for the decimal point, such as "3.14"
, specify the «decimal» parameter to be ','
. («decimal» requires Analytica 5.0)
Library
Text Functions
Example
ParseNumber('3.14') → 3.14
ParseNumber( x, x )
{ Keeps cells that don't parse as text }ParseNumber('3,14', decimal:',') → 3.14
Notes
If «x» is an array, it will try to parse each element of the array -- it fully supportsIntelligent Arrays, like most Analytica functions.
ParseNumber is often useful when reading data from flat files, using ReadCsvFile or ReadTextFile. You don't need to use ParseNumber when using ParseCSV, since it parses it.
You can coerce a text to be numeric in other ways. For example, you can declare a function parameter with the qualifiers "Coerce Numeric". If the actual parameter is text, it will try to coerce it to a number when it calls the function. The Number format of the variable that contains the call to the function determines how the value is interpreted. Usually, it should not be a date number format.
History
- ParseNumber was introdued to Analytica 4.2 as a built-in function.
- The «decimal» parameter was introduced in Analytica 5.0
See Also
- ParseNum
- NumberToText
- Number format
- NumberFormat attribute
- Binary and hexadecimal integer formats
- Base Conversion Function Library
- ParseDate
- ReadTextFile
- ReadCsvFile
- Text functions
- Function Parameter Qualifiers (especially the coerce qualifier)
Enable comment auto-refresher