toFixed is busted, workaround

This commit is contained in:
ed 2021-08-26 00:51:35 +02:00
parent 6452e927ea
commit 71096182be
2 changed files with 16 additions and 12 deletions

View file

@ -236,7 +236,7 @@ function U2pvis(act, btns) {
p = r.perc(nb, 0, fobj.size, fobj.t_hashing);
fo.hp = '{0}%, {1}, {2} MB/s'.format(
p[0].toFixed(2), p[1], p[2].toFixed(2)
f2f(p[0], 2), p[1], f2f(p[2], 2)
);
if (!r.is_act(fo.in))
return;
@ -258,7 +258,7 @@ function U2pvis(act, btns) {
var p = r.perc(fo.bd, fo.bd0, fo.bt, fobj.t_uploading);
fo.hp = '{0}%, {1}, {2} MB/s'.format(
p[0].toFixed(2), p[1], p[2].toFixed(2)
f2f(p[0], 2), p[1], f2f(p[2], 2)
);
if (!r.is_act(fo.in))
@ -903,7 +903,7 @@ function up2k_init(subtle) {
td = (now - (etaref || now)) / 1000.0;
etaref = now;
ebi('acc_info').innerHTML = st.time.busy.toFixed(1) + ' ' + (now / 1000).toFixed(1);
ebi('acc_info').innerHTML = f2f(st.time.busy, 1) + ' ' + f2f(now / 1000, 1);
if (!nhash)
ebi('u2etah').innerHTML = 'Done ({0}, {1} files)'.format(humansize(st.bytes.hashed), pvis.ctr["ok"] + pvis.ctr["ng"]);

View file

@ -401,16 +401,20 @@ function s2ms(s) {
}
function f2f(val, nd) {
// 10.toFixed(1) returns 10.00 for certain values of 10
val = (val * Math.pow(10, nd)).toFixed(0).split('.')[0];
return nd ? (val.slice(0, -nd) || '0') + '.' + val.slice(-nd) : val;
}
function humansize(b, terse) {
var i=0, u=terse? ['B','K','M','G'] : ['B','KB','MB','GB'];
while (b >= 1000 && i<u.length) {
b /= 1024;
i += 1;
}
u = ' ' + u[i];
if (b>=100) return Math.floor(b) + u;
if (b>=10) return b.toFixed(1) + u;
return b.toFixed(2) + u;
var i = 0, u = terse ? ['B', 'K', 'M', 'G'] : ['B', 'KB', 'MB', 'GB'];
while (b >= 1000 && i < u.length) {
b /= 1024;
i += 1;
}
return f2f(b, b >= 100 ? 0 : b >= 10 ? 1 : 2) + ' ' + u[i];
}