Difference between revisions of "ParseNumber"
m |
(«decimal» parameter) |
||
Line 3: | Line 3: | ||
[[Category:Doc Status D]] <!-- For Lumina use, do not change --> | [[Category:Doc Status D]] <!-- For Lumina use, do not change --> | ||
− | ==ParseNumber(x) == | + | ==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. <code>ParseNumber("hello")</code>, it returns [[Null]] | + | 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. <code>ParseNumber("hello")</code>, 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 <code>"3.14"</code>, specify the «decimal» parameter to be <code>','</code>. («decimal» requires [[Analytica 5.0]]) | ||
== Library == | == Library == | ||
Line 10: | Line 12: | ||
== Example == | == Example == | ||
− | :<code>ParseNumber( | + | |
+ | :<code>[[ParseNumber]]('3.14') → 3.14</code> | ||
+ | :<code>[[ParseNumber]]( x, x )</code> { ''Keeps cells that don't parse as text'' } | ||
+ | :<code>[[ParseNumber]]('3,14', decimal:',') → 3.14</code> | ||
== Notes == | == Notes == | ||
An array can be passed, in which each cell of the array is parsed. | An array can be passed, in which each cell of the array is parsed. | ||
− | [[ParseNumber]] is often useful when reading data from flat files, using [[ReadCsvFile]] or [[ReadTextFile]]. | + | [[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. |
Coercion to numeric can be accomplished in Analytica in other ways. For example, you can declare a function parameter with the [[Function Parameter Qualifiers|qualifiers]] "coerce numeric". Then a string value passed to that parameter is parsed. The calling variable needs to have a non-date number format, since the number format of the calling object determines how the value is interpreted. | Coercion to numeric can be accomplished in Analytica in other ways. For example, you can declare a function parameter with the [[Function Parameter Qualifiers|qualifiers]] "coerce numeric". Then a string value passed to that parameter is parsed. The calling variable needs to have a non-date number format, since the number format of the calling object determines how the value is interpreted. | ||
==History== | ==History== | ||
− | [[ParseNumber]] is new to [[What's new in Analytica 4.2?|Analytica 4.2]] as a built-in function, but an equivalent library function, [[ParseNum]] can be used in Analytica 4.1. | + | * [[ParseNumber]] is new to [[What's new in Analytica 4.2?|Analytica 4.2]] as a built-in function, but an equivalent library function, [[ParseNum]] can be used in Analytica 4.1. |
+ | * The «decimal» parameter was introduced in [[Analytica 5.0]] | ||
== See Also == | == See Also == |
Revision as of 22:48, 9 September 2016
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
An array can be passed, in which each cell of the array is parsed.
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.
Coercion to numeric can be accomplished in Analytica in other ways. For example, you can declare a function parameter with the qualifiers "coerce numeric". Then a string value passed to that parameter is parsed. The calling variable needs to have a non-date number format, since the number format of the calling object determines how the value is interpreted.
History
- ParseNumber is new to Analytica 4.2 as a built-in function, but an equivalent library function, ParseNum can be used in Analytica 4.1.
- 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