Home >Web Front-end >JS Tutorial >How to convert characters into numbers in javascript
Conversion method: 1. Use Number() function, syntax "Number(value)"; 2. Use parseInt() function, syntax "parseInt("value")"; 3. Use parseFloat() function , syntax "parseFloat("value")".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
javascript converts characters into numbers
Method 1: Use the Number() function
Syntax: Number(value)
Number() can convert the parameter value into a number.
console.log(Number("1")); //返回数值1 console.log(Number(true)); //返回数值1
Method 2: Use the parseInt() function
parseInt() can convert the value into an integer.
console.log(parseInt("123abc")); //返回数字123 console.log(parseInt("1.73")); //返回数字1
Method 3: Use the parseFloat() function
parseFloat() can convert the value to a floating point number.
console.log(parseFloat("1.234.5")); //返回数值 1.234
[Recommended learning: javascript advanced tutorial]
The above is the detailed content of How to convert characters into numbers in javascript. For more information, please follow other related articles on the PHP Chinese website!