# Javascript rounds math.round of and math.pow of

• 2020-03-30 01:06:23
• OfStack

``````
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<title>Javascript rounded (Math.round() with Math.pow())</title>
<script type="text/javascript">
//Math. Round (x); Returns the nearest integer to the number, rounded to the integer, that is, to the decimal part
function f(){
}
//Math.h pow (x, y); Returns the specified power of the base
//Returns a numerical expression in terms of x to the y, equal to x to the y
//Returns Infinity if the pow parameter is too large and causes floating point overflow
function f1(){
alert(Math.pow(2,10));//2 to the 10th is equal to 1024
alert(Math.pow(1024,0.1));//1024 to the 0.1 power is equal to 2
}

function ForDight(Dight,How){
Dight = Math.round(Dight*Math.pow(10,How))/Math.pow(10,How);
return Dight;
}
function f2(){
}
//Another way to round it is the same principle.
//Num is the data to be converted. N is the number of bits to be converted
//cheng(123.456,2);// Keep two decimal places
function cheng(num,n){
var dd=1;
var tempnum;
for(i=0;i<n;i++){
dd*=10;
}
tempnum = num*dd;
tempnum = Math.round(tempnum);