ToNumber - method of the Pm object

Conversion to numeric value.
Double ToNumber(Variant Value)
Value(Variant) Value to be converted to number. The conversion depends on the data type of the value:
- string: It is converted to number based on the string content. The decimal separator may be represented by "period" or "comma" character - the method can handle both characters. It means that 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 string) and must not contain any invalid characters (except for spaces and tabs in front 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
If it is not possible to convert the value to number (e.g. there is no numeric value in the string), then the method returns a special numeric value NaN (= Not a Number) - it can be tested by the Pm.IsValid method.

This method is functional also in Macro expression $.expr and in the onDraw event of the PmgCanvas object.
This method is also functional in Web panels.
JavaScriptVBScriptSelect and copy to clipboard

var v = Pm.ToNumber("3.14");   // returns 3.14
v = Pm.ToNumber("3,14");   // returns 3.14
v = Pm.ToNumber(" 3.14 ");   // returns 3.14
v = Pm.ToNumber("");   // returns NaN
v = Pm.ToNumber(" ");   // returns NaN
v = Pm.ToNumber(true);   // returns 1
v = Pm.ToNumber(false);   // returns 0
v = Pm.ToNumber(null);   // returns 0
v = Pm.ToNumber(undefined);   // returns NaN
v = Pm.ToNumber(3.14);   // returns 3.14

Pm8.02.01: Created
PROMOTIC 9.0.27 SCADA system documentation MICROSYS, spol. s r.o.

Send page remarkContact responsible person
- Pm
- Abs
- Cos
- E
- Exp
- LN2
- PI
- Pow
- Sin
- Tan
- ToNumber
© MICROSYS, spol. s r.o.