首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

javaScript 保存小数并四舍五入的方法

2012-11-16 
javaScript 保留小数并四舍五入的方法使用toFixed()函数html head /headscript languagejavascri

javaScript 保留小数并四舍五入的方法

使用toFixed()函数

<html> <head> </head>  <script language="javascript">     document.write("<h1>JS保留两位小数例子</h1><br>");         var a=2.1512131231231321;       document.write("原来的值:"+a+"<br>");       document.write("两位小数点:"+a.toFixed(2)+"<br>四位小数点"+a.toFixed(4));   </script> <body> </body> </html> 

??

热点排行