<script type="text/javascript">
function round(a,b)
{
debugger;
var g =(Math.round(a*Math.pow(10,b))*Math.pow(10,-b));
return g ;
}
alert(round(0.94,2));
alert(round(0.93,2));
alert(round(0.95,2));
alert(round(0.96,2));
</script>94*0.01=0.9400000000000001
93*0.01=0.93
94*0.1=9.4
94*0.001=0.094
这到底是为什么,谁能回答一下
function round(a,b)
{
debugger;
var g =(Math.round(a*Math.pow(10,b))*Math.pow(10,-b));
return g ;
}
alert(round(0.94,2));
alert(round(0.93,2));
alert(round(0.95,2));
alert(round(0.96,2));
</script>94*0.01=0.9400000000000001
93*0.01=0.93
94*0.1=9.4
94*0.001=0.094
这到底是为什么,谁能回答一下
function round(a,b)
{
debugger;
var g =(Math.round(a*Math.pow(10,b))/Math.pow(10,b));
return g ;
}
function showInPage(output) {
document.write(output + "<br />");
}
showInPage(round(0.94,2));
showInPage(round(0.93,2));
showInPage(round(0.95,2));
showInPage(round(0.96,2));
showInPage("<hr />");
Math.round
Math.pow
两个方法.