parseInt
parseInt is used to convert a string value into an integer. It returns the first integer contained in the string or NaN (Not a Number) if the string does not begin with an integer. It is a method of the Global Object. The Global Object has no syntax, so its methods can be called directly.
The expression
parseInt(string{,radix})parses the string as an integer of base radix. radix is optional and is a value between 2 and 36 indicating the base of the number contained in string. If not supplied, strings with a prefix of '0x' are considered hexadecimal and strings with a prefix of '0' are considered octal. All other strings are considered decimal... Usually you want numbers to be treated as decimals, and since a leading zero would indicate that the number is an octal number (go to Numeric for more information), it is a good idea to always include the base 10 when using parseInt
The function will read numbers from the beginning of the string and will stop when the first non-digit is reached:
parseInt("123xyz",10)returns 123
parseInt("xyz123",10)returns NaN (not a number) since the first character is not a number.
parseFloat
parseFloat returns a floating-point number converted from a string. It is a method of the Global Object. The Global Object has no syntax, so its methods can be called directly:
parseFloat(numString)The required numString argument is a string that contains a floating-point number. The function will read numbers from the beginning of the string and will stop at the first character that cannot be interpreted as part of a floating-point number. If the string does not begin with a floating-point number, NaN will be returned.
parseFloat("2.1e4xyz")returns 21000 (2.1 * 104).
isNaN
The isNaN method returns true if the value is NaN, and false otherwise. It is a method of the Global Object. The Global Object has no syntax, so its methods can be called directly: You typically use this function to test return values from the parseInt and parseFloat methods.
isNaN(num)num is a numeric value to test.
isFinite
The isFinite method returns true if the value is any other value than NaN, negative infinity or positive infinity. If it is any of those three, it returns false. It is a method of the Global Object. The Global Object has no syntax, so its methods can be called directly:
isFinite(num)num is a numeric value to test.
toString
toString is a method of the Object object, which means it is available in any other JScript .NET object. It is used to convert a variable into a string. Sometimes this must be done to a variable before inserting it in a question with the set method (go to get and set for more information).
valueOf
valueOf is a method of the Object object, which means it is available in any other JScript .NET object. It returns the primitive value of the specified object, i.e. the numeric value of a number, the string value of a string etc.