Promotic
WikipediaLinkedInYoutubeTwitterFacebook

ToNumber - method of object Pm

Description:
Conversion to numeric value
Syntax:
ToNumber(Value As Variant) As Double
Calling:
n = Pm.ToNumber(Value)
Parameters:
Value(Variant) Value to be converted to number. The conversion depends on the data type of the value:
- string: is converted to number based on the string content. The movable separator may be represented by "period" or "comma" - the method can handle both characters. I.e. both the strings "3.14" and "3,14" are converted to identical number 3.14. In the string there must be the number itself (must not be empty) and must not contain any invalid characters (except for spaces and tabs infront of the number and after the number).
- boolean: true returns 1, false returns 0
- undefined/empty: returns NaN
- null: returns 0
- nothing: returns 0 (only for VBScript, in JavaScript the null is used))
- object: returns NaN
- array: returns NaN
- number: is left unaltered
Note:
If it is not possible to convert the value to number (e.g. there is no numeric value in the string), the method returns a special numeric value NaN (= Not a Number) - it can be tested by the Pm.IsValid method.
 
The method can also be called in the graphic item events for Web Panels.

The method is functional also in Macro expression $.expr.

Example:
Pm.ToNumber("3.14") ... returns 3.14
Pm.ToNumber("3,14") ... returns 3.14
Pm.ToNumber(" 3.14 ") ... returns 3.14
Pm.ToNumber("") ... returns NaN
Pm.ToNumber(" ") ... returns NaN
Pm.ToNumber(true) ... returns 1
Pm.ToNumber(false) ... returns 0
Pm.ToNumber(null) ... returns 0
Pm.ToNumber(undefined) ... returns NaN
Pm.ToNumber(3.14) ... returns 3.14
Navigation:
 
- Pm
 
- Abs
- Cos
- E
- Exp
- LN2
- PI
- Pow
- Sin
- Tan
- ToNumber
 
 
© MICROSYS, spol. s r. o.Tavičská 845/21 703 00 Ostrava-Vítkovice