Number.tofixed (x) is the x bit after the specified number is intercepted, and number.toprecision (x) intercepts the entire number to the specified (x) length. Note that one calculates the length of the decimal point, and one is the length of the whole number.
The code is as follows |
Copy Code |
<script type= "Text/javascript" >
var aa = 2.3362;
document.write (aa.tofixed (1)); 2.3 document.write (aa.tofixed (2)); 2.34
document.write (Aa.toprecision (2)); 2.3 document.write (Aa.toprecision (3)); 2.34
document.write (Math.Round (AA * 10)/10); 2.3 document.write (Math.Round (AA * 100)/100); 2.34
</script> |
In the Javascript 1.5 (ie5.5+, ns6+ version support), there are 2 new functions specifically used in Money circulation:
Number.tofixed (x) and Number.toprecision (x).
Round method
Function: Returns the nearest integer to the given numeric expression.
Syntax: Math.Round (number), the required number argument is the value to round to the nearest integer.
Note: If the decimal part of number is greater than or equal to 0.5, the return value is the smallest integer greater than the. Otherwise, round returns the largest integer less than or equal to number.
Example:
If you take one, multiply it by 10 and then divide by 10, and so on.
The code is as follows |
Copy Code |
Math.Round (3.248 * 100)/100
|