夜的第七章

WEB开发个人博客。

« javascript 动态创建表格:新增、删除行和单元格农村小姑娘的麻辣作文+老师批语 »

javascript 四舍五入函数

/*  

*     ForDight(Dight,How):数值格式化函数,Dight要  

*     格式化的   数字,How要保留的小数位数。  

*/  

function   ForDight(Dight,How)  

{  

            Dight   =   Math.round   (Dight*Math.pow(10,How))/Math.pow(10,How);  

            return   Dight;  

}  

alert(ForDight(12345.67890,2));  

</script>

<table border="1" width="90%" cellspacing="0" cellpadding="0" bordercolor="#000000" bordercolorlight="#000000" bordercolordark="#FFFFFF" style="font-size:12px;color:black">

     <tr>

       <td width="100%">四舍五入:格式:.**<input type="text" name="textfield" onblur="this.value=Math.round(parseFloat(this.value)*100)/100" onKeyUp="this.value=this.value.replace(/[^0-9.]/,'');">

       </td>

     </tr>

     <tr>

       <td width="100%">四舍五入:格式:.***<input type="text" name="textfield" onblur="this.value=Math.round(parseFloat(this.value)*1000)/1000" onKeyUp="this.value=this.value.replace(/[^0-9.]/,'');">

       </td>

     </tr>

   </table>

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。



[2007 - 2011] © Leadnt.com