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 can 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 |
---|
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