createtime--2017 August 23 11:03:31
Author:marydon
JS set percentage reserved two decimal places
Error usage:
var percent = (num1/num2) * 100%;
Correct usage:
var percent = Math.Round (NUM1/NUM2 * 10000)/100 + "%";
Description
1.math.round (num) indicates that NUM is rounded, preserving only the integer digits, such as num=0.49, and returning a result of 0, such as num=0.51, which returns a result of 1;
2. Convert the results to percentages and retain 2 decimal places:
Ideas:
2.1 will enlarge the result of num1/num2 100 times times;
2.2 retains 2 decimal places for magnified results.
2.3 retains 2 decimal places and needs to use the Math.Round (num) function;
2.4 because the Math.Round (NUM) function retains only the integer digits, it needs to be magnified 100 times times at least again;
2.5 After rounding, divided by the magnification of multiples, stitching on the '% ' can be.
Example:
num1/num2=0.57823--> magnification 100 times times:57.823--> need to retain 2 bits, at least 100 times times more magnification:5782.3--> use Math.Round () for rounding operations:5782--> Zoom in and out again (+):57.82--> stitching percent sign: 57.82%
JS set percentage reserved two decimal places