转载自:http://shanxmxj.iteye.com/blog/403969
<script language="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>
本文介绍了一个简单的JavaScript函数ForDight,用于格式化数字并保留指定小数位数。该函数利用Math.round方法结合Math.pow进行四舍五入操作。
796

被折叠的 条评论
为什么被折叠?



