Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix display of size values in web interface #2703

Merged
merged 5 commits into from
Feb 24, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 9 additions & 7 deletions web/src/formatter.js
Expand Up @@ -9,21 +9,23 @@ const number_format = new Intl.NumberFormat(current_locale);

const kilo = 1000;
const mem_formatters = [
new Intl.NumberFormat(current_locale, { style: 'unit', unit: 'byte' }),
new Intl.NumberFormat(current_locale, { style: 'unit', unit: 'kilobyte' }),
new Intl.NumberFormat(current_locale, { style: 'unit', unit: 'megabyte' }),
new Intl.NumberFormat(current_locale, { style: 'unit', unit: 'gigabyte' }),
new Intl.NumberFormat(current_locale, { style: 'unit', unit: 'terabyte' }),
new Intl.NumberFormat(current_locale, { style: 'unit', unit: 'petabyte' }),
new Intl.NumberFormat(current_locale, { style: 'unit', unit: 'byte', maximumFractionDigits: 0 }),
new Intl.NumberFormat(current_locale, { style: 'unit', unit: 'kilobyte', maximumFractionDigits: 0 }),
new Intl.NumberFormat(current_locale, { style: 'unit', unit: 'megabyte', maximumFractionDigits: 0 }),
new Intl.NumberFormat(current_locale, { style: 'unit', unit: 'gigabyte', maximumFractionDigits: 2 }),
new Intl.NumberFormat(current_locale, { style: 'unit', unit: 'terabyte', maximumFractionDigits: 2 }),
new Intl.NumberFormat(current_locale, { style: 'unit', unit: 'petabyte', maximumFractionDigits: 2 }),
];

const fmt_kBps = new Intl.NumberFormat(current_locale, {
style: 'unit',
unit: 'kilobyte-per-second',
maximumFractionDigits: 2,
});
const fmt_MBps = new Intl.NumberFormat(current_locale, {
style: 'unit',
unit: 'megabyte-per-second',
maximumFractionDigits: 2,
});

export const Formatter = {
Expand Down Expand Up @@ -51,7 +53,7 @@ export const Formatter = {
let size = bytes;
for (const nf of mem_formatters) {
if (size < kilo) {
return nf.format(Math.floor(size));
return nf.format(size);
}
size /= kilo;
}
Expand Down