回复 19楼 liunis
WIN7_x64 G2020+8G
2.7M,得75秒左右。
TEXT TO jsCode TEXTMERGE NOSHOW PRETEXT 7 // 例1:js 字节转换成 B KB MB GB 的方法 function sizeTostr(size) { var data = ""; if (size < 0.1 * 1024) { //如果小于0.1KB转化成B data = size.toFixed(2) + "B"; } else if (size < 0.1 * 1024 * 1024) {//如果小于0.1MB转化成KB data = (size / 1024).toFixed(2) + "KB"; } else if (size < 0.1 * 1024 * 1024 * 1024) { //如果小于0.1GB转化成MB data = (size / (1024 * 1024)).toFixed(2) + "MB"; } else { //其他转化成GB data = (size / (1024 * 1024 * 1024)).toFixed(2) + "GB"; } var sizestr = data + ""; var len = sizestr.indexOf("\."); var dec = sizestr.substr(len + 1, 2); if (dec == "00") {//当小数点后为00时 去掉小数部分 return sizestr.substring(0, len) + sizestr.substr(len + 3, 2); } return sizestr; } // 例2:js实现KB、MB、GB、TB单位转换 // c 参数:表示要被转化的容量大小,以字节为单 // b 参数:表示如果转换时出小数,四舍五入保留多少位 默认为2位小数 function formatBytes(a, b) { if (0 == a) return "0 B"; var c = 1024, d = b || 2, e = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"], f = Math.floor(Math.log(a) / Math.log(c)); return parseFloat((a / Math.pow(c, f)).toFixed(d)) + " " + e[f]; } ENDTEXT js = CREATEOBJECT("ScriptControl") js.Language = "JavaScript" js.AddCode(jsCode) ? "例1:js 字节转换成 B KB MB GB 的方法" ? js.run("sizeTostr", 1000) ? js.run("sizeTostr", 102400) ? js.run("sizeTostr", 10240000) ? js.run("sizeTostr", 1000111111) ? ? "例2:js实现KB、MB、GB、TB单位转换" ? js.run("formatBytes",1234) ? js.run("formatBytes",1234, 3) ? js.run("formatBytes",123400, 3) ? js.run("formatBytes",12340000, 3) ? js.run("formatBytes",12340000000, 3) ? js.run("formatBytes",12340000000000, 3) ? js.run("formatBytes",1234000000000000, 3)
Clear ? FormatBytes(1234) ? FormatBytes(123400) ? FormatBytes(12340000) ? FormatBytes(12340000000) ? FormatBytes(12340000000000) ? FormatBytes(1234000000000000) ? FormatBytes(1234000000000000000) Function FormatBytes(tnSize) Local nLow, nHigh, nLen, cBuff m.nLow = Mod(m.tnSize, 0x100000000) m.nHigh = Int(m.tnSize / 0x100000000) m.nLen = 20 m.cBuff = Replicate(Chr(0), m.nLen) StrFormatByteSize64(m.nLow, m.nHigh, @ m.cBuff, m.nLen) Return Rtrim(m.cBuff, Chr(0)) EndFunc Function StrFormatByteSize64(low64, high64, pszBuf, cchBuff) Declare Long StrFormatByteSize64 in shlwapi Long, Long, String @, Long Return StrFormatByteSize64(m.low64, m.high64, m.pszBuf, m.cchBuff) EndFunc