原文地址http://blog.csdn.net/he20101020/article/details/8503308 <script type="text/javascript"> //保留两位小数 //功能:将浮点数四舍五入,取小数点后2位 function toDecimal(x) { var f = parseFloat(x); if (isNaN(f
js保留2位小数toFixed(xxxx) var a = 9.39393; alert(a.toFixed()); alert(Number.toFixed(9.39393)); 返回的是9. 对于一些小数点后有多位的浮点数,我们可能只需要保留2位,但js没有提供这样直接的函数,所以我们得自己写函数实现这个功能,代码如下: function changeTwoDecimal(x) { var f_x = parseFloat(x); if (isNaN(f_x)) { alert('funct
前言 为了获得一堆apk的大小,并与人类友好方式显示.本来是打算用以下方法,到时不能具体到保留两位小数. org.apache.commons.io.FileUtils.byteCountToDisplaySize(f.length()); Returns a human-readable version of the file size, where the input represents a specific number of bytes. If the size is over 1GB