Difference between revisions of "ParseNum"

m
Line 3: Line 3:
 
[[Category:Doc Status D]] <!-- For Lumina use, do not change -->
 
[[Category:Doc Status D]] <!-- For Lumina use, do not change -->
  
= ParseNum(x) =
+
== ParseNum(x) ==
  
Parses a string to a numeric value.   
+
Parses string «x» to a numeric value.  If «x» is already numeric, «x» is returned.
  
In [[What's new in Analytica 4.2?|Analytica 4.2]] or later, you can use use [[ParseNumber]], which is built-in.
+
== Library ==
 
 
= Library =
 
  
 
Flat File Library.ana
 
Flat File Library.ana
Line 15: Line 13:
 
(Use '''File &rarr; Add Library...''' to add this library)
 
(Use '''File &rarr; Add Library...''' to add this library)
  
= Example =
+
== Example ==
  
ParseNum("3.14") &rarr; 3.14
+
:<code>ParseNum("3.14") &rarr; 3.14</code>
  
= Notes =
+
== Notes ==
 
+
An array can be passed, in which each cell of the array is parsed.
If x is already numeric, x is returned.
 
  
An array can be passed, in which each cell of the array is parsed.
+
When «x» does not parse as a numeric value, such as <code>ParseNum("hello")</code>, the following error occurs:
  
When x does not parse as a numeric value, such as ParseNum("hello"), the following error occurs:
+
''Evaluation Error: In the call to function Coerce_to_numeric, a value passed to the first parameter, x, could not be coerced to type Numeric, while evaluating function ParseNum.''
:''Evaluation Error: In the call to function Coerce_to_numeric, a value passed to the first parameter, x, could not be coerced to type Numeric, while evaluating function ParseNum.''
 
  
ParseNum is often useful when reading data from flat files, using [[ReadCsvFile]] or [[ReadTextFile]].
+
[[ParseNum]] is often useful when reading data from flat files, using [[ReadCsvFile]] or [[ReadTextFile]].
  
 
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.
  
= See Also =
+
In [[What's new in Analytica 4.2?|Analytica 4.2]] or later, you can use use [[ParseNumber]], which is a built-in function.
  
 +
== See Also ==
 
* [[ParseNumber]]
 
* [[ParseNumber]]
 
* [[ParseDate]]
 
* [[ParseDate]]
* [[ReadTextFile]], [[ReadCsvFile]]
+
* [[ReadTextFile]]
 +
* [[ReadCsvFile]]
 
* [[Function Parameter Qualifiers]] (especially the '''coerce''' qualifier)
 
* [[Function Parameter Qualifiers]] (especially the '''coerce''' qualifier)

Revision as of 21:57, 14 January 2016


ParseNum(x)

Parses string «x» to a numeric value. If «x» is already numeric, «x» is returned.

Library

Flat File Library.ana

(Use File → Add Library... to add this library)

Example

ParseNum("3.14") → 3.14

Notes

An array can be passed, in which each cell of the array is parsed.

When «x» does not parse as a numeric value, such as ParseNum("hello"), the following error occurs:

Evaluation Error: In the call to function Coerce_to_numeric, a value passed to the first parameter, x, could not be coerced to type Numeric, while evaluating function ParseNum.

ParseNum is often useful when reading data from flat files, using ReadCsvFile or ReadTextFile.

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.

In Analytica 4.2 or later, you can use use ParseNumber, which is a built-in function.

See Also

Comments


You are not allowed to post comments.