ToNumber - method of object Pm

Conversion to numeric value
ToNumber(Value As Variant) As Double
n = Pm.ToNumber(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" - 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 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
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.
The method can also be called in the graphic item events for Web panels.

The method is functional also in Macro expression $.expr and in the onDraw event of the PmiCanvas graphic item.

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
PROMOTIC 8.3.30 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.Tavičská 845/21 703 00 Ostrava-Vítkovice