diff --git a/next-i18next.config.js b/next-i18next.config.js index cef9e3988..ac1eac369 100644 --- a/next-i18next.config.js +++ b/next-i18next.config.js @@ -136,7 +136,7 @@ module.exports = { const dm = options.decimals ? options.decimals : 0; - const i = options.binary ? 2 : Math.floor(Math.log(value) / Math.log(k)); + const i = Math.floor(Math.log(value) / Math.log(k)); const formatted = new Intl.NumberFormat(lng, { maximumFractionDigits: dm, minimumFractionDigits: dm }).format( parseFloat(value / k ** i), diff --git a/src/utils/rate-formatter.test.js b/src/utils/rate-formatter.test.js index c49459c0c..d3f36bcba 100644 --- a/src/utils/rate-formatter.test.js +++ b/src/utils/rate-formatter.test.js @@ -27,11 +27,11 @@ describe("rate formatter", () => { it.each([ ["zero bytes", 0, { binary: true, bits: false, decimals: 1 }, "0 B/s"], ["decimal bytes", 15_000, { binary: false, bits: false, decimals: 1 }, "15.0 kB/s"], - ["binary bytes as mebibytes", 512, { binary: true, bits: false, decimals: 1 }, "0.0 MiB/s"], - ["binary kibibytes as mebibytes", 15 * 1024, { binary: true, bits: false, decimals: 1 }, "0.0 MiB/s"], + ["binary bytes", 512, { binary: true, bits: false, decimals: 1 }, "512.0 B/s"], + ["binary kibibytes", 15 * 1024, { binary: true, bits: false, decimals: 1 }, "15.0 kiB/s"], ["binary mebibytes", 15 * 1024 ** 2, { binary: true, bits: false, decimals: 1 }, "15.0 MiB/s"], - ["binary gibibytes as mebibytes", 2 * 1024 ** 3, { binary: true, bits: false, decimals: 1 }, "2,048.0 MiB/s"], - ["binary bits as mebibits", 15 * 1024, { binary: true, bits: true, decimals: 1 }, "0.0 Mibit/s"], + ["binary gibibytes", 2 * 1024 ** 3, { binary: true, bits: false, decimals: 1 }, "2.0 GiB/s"], + ["binary bits", 15 * 1024, { binary: true, bits: true, decimals: 1 }, "15.0 kibit/s"], ])("formats %s", (_description, value, options, expected) => { expect(formatRate(value, "en", options)).toBe(expected); });