Fix number formatting for 1000, 10000, ...
Some checks are pending
test-and-build / test-and-build (push) Waiting to run
Some checks are pending
test-and-build / test-and-build (push) Waiting to run
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
2b23f1488c
commit
36359bdcb8
1 changed files with 4 additions and 4 deletions
|
@ -12,15 +12,15 @@ export function formatNumber(number, thousandSep = ' ', decimalSep = '.', places
|
||||||
return result + number.toFixed(places)
|
return result + number.toFixed(places)
|
||||||
}
|
}
|
||||||
|
|
||||||
let place = Math.ceil(Math.log10(number))
|
const place = Math.floor(Math.log10(number))
|
||||||
|
|
||||||
if (place < 3) {
|
if (place < 3) {
|
||||||
return result + number.toFixed(places).replace('.', decimalSep)
|
return result + number.toFixed(places).replace('.', decimalSep)
|
||||||
}
|
}
|
||||||
|
|
||||||
while (place--) {
|
for (let i = place; i >= 0; i--) {
|
||||||
result += number / 10 ** place % 10 | 0
|
result += number / 10 ** i % 10 | 0
|
||||||
if (place > 0 && place % 3 === 0) {
|
if (i > 0 && i % 3 === 0) {
|
||||||
result += thousandSep
|
result += thousandSep
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue