FIX: makes sure [999500..999999] is correctly shown as 999k

This commit is contained in:
Joffrey JAFFEUX 2018-03-02 11:00:48 +01:00 committed by GitHub
parent 642c60c310
commit 6d4ff05cf0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -311,7 +311,7 @@ export function number(val) {
formattedNumber = I18n.toNumber(val / 1000000, {precision: 1});
return I18n.t("number.short.millions", {number: formattedNumber});
} else if (val > 99999) {
formattedNumber = I18n.toNumber(val / 1000, {precision: 0});
formattedNumber = I18n.toNumber(Math.floor(val / 1000), {precision: 0});
return I18n.t("number.short.thousands", {number: formattedNumber});
} else if (val > 999) {
formattedNumber = I18n.toNumber(val / 1000, {precision: 1});

View File

@ -211,6 +211,8 @@ QUnit.test("number", assert => {
assert.equal(number(NaN), "0", "it returns 0 for NaN");
assert.equal(number(3333), "3.3k", "it abbreviates thousands");
assert.equal(number(2499999), "2.5M", "it abbreviates millions");
assert.equal(number(1000000), "1.0M", "it abbreviates a million");
assert.equal(number(999999), "999k", "it abbreviates hundreds of thousands");
});
QUnit.test("durationTiny", assert => {