Method: 1. Use the replace() method to remove the percent sign from the percentage. The syntax is "Percent object.replace("%","")"; 2. Use the "/" operator to remove the To divide the number with the percent sign by 100, the syntax is "percentage minus the percent sign/100"; 3. Output the percentage that has been divided by 100.
The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.
The replace() method is used to replace some characters with other characters in a string, or to replace a substring that matches a regular expression.
Syntax
stringObject.replace(regexp/substr,replacement)
Return value
A new string obtained by replacing the first match or all matches of regexp with replacement.
Convert percentage to decimal
1. Remove the percent sign first
2. Then divide by 100
3. Return out
Examples are as follows:
Output results:
Related recommendations:javascript learning tutorial
The above is the detailed content of How to convert percentage to decimal in javascript. For more information, please follow other related articles on the PHP Chinese website!