move formatBytes to util.js

This commit is contained in:
stoffu
2018-08-23 12:46:56 +09:00
parent ee8a9beca8
commit f09cf7e0dc
7 changed files with 17 additions and 66 deletions
+11
View File
@@ -1,3 +1,14 @@
// https://stackoverflow.com/a/18650828
function formatBytes(bytes, decimal) {
if (0 == bytes)
return "0 bytes";
var c = 1024;
var d = decimal || 2;
var e = ["bytes", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
var f = Math.floor(Math.log(bytes) / Math.log(c));
return "<b>" + parseFloat((bytes / Math.pow(c, f)).toFixed(d)) + "</b> " + e[f]
}
function print_money(amount, decimal_point) {
var s1 = String(amount);
while (s1.length < decimal_point+1)