Writing method:Number (variable name). For example:
var a="100"; //Stringalert(Number(a)+100); //turn out200
Specific situation:
1. If the string is preceded by 0 or other symbols, JS will automatically ignore it.
For example:
var a="000100"; alert(Number(a)); //The result is 100var b="+100"; alert(Number(b)); //turn out100
2. If the string is empty or space, it will be converted to 0.
For example:
var a=""; alert(Number(a)); //turn out0
3. If true is converted to 1, false is converted to 0
For example:
var a=true; alert(Number(a)); //The result is 1var b=false; alert(Number(b)); //turn out0
4. If it is a function, object, json, undefined, it will be converted to NAN, indicating that it cannot be converted.
5. If it is an array
①Empty array, then convert to 0
For example:
var a=[""]; alert(Number(a)); //turn out0
② If the array has content to convert it into corresponding content, there cannot be too many, only one can be converted. If the array contains multiple elements, the result is NAN
For example:
var a=[1] alert(Number(a)); //The result is 1var b=[1,2] alert(Number(b)); //turn outNAN
6. If it is null, it will be converted to 0
This is the article about converting strings into numbers in Vue. For more related contents of converting vue strings into numbers, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!