You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
838 B
27 lines
838 B
6 years ago
|
// 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]
|
||
|
}
|
||
|
|
||
6 years ago
|
function print_money(amount, decimal_point) {
|
||
|
var s1 = String(amount);
|
||
|
while (s1.length < decimal_point+1)
|
||
|
s1 = "0" + s1;
|
||
|
var s2 = "";
|
||
|
for (var i = 0; i < decimal_point; ++i)
|
||
|
s2 = s1[s1.length - 1 - i] + s2;
|
||
|
s2 = "." + s2;
|
||
|
for (var i = 0; i < s1.length - decimal_point; ++i) {
|
||
|
if (i > 0 && i % 3 == 0)
|
||
|
s2 = "," + s2;
|
||
|
s2 = s1[s1.length - 1 - decimal_point - i] + s2
|
||
|
}
|
||
|
return s2;
|
||
|
}
|