mirror of
https://github.com/TeamPiped/Piped.git
synced 2024-12-13 13:50:27 +05:30
Merge pull request #1608 from thecashewtrader/number-localisation
Localize numbers using Internalisation API
This commit is contained in:
commit
5f9ac9ed3f
16
src/main.js
16
src/main.js
@ -88,20 +88,8 @@ const mixin = {
|
||||
return str;
|
||||
},
|
||||
numberFormat(num) {
|
||||
const digits = 2;
|
||||
const si = [
|
||||
{ value: 1, symbol: "" },
|
||||
{ value: 1e3, symbol: "k" },
|
||||
{ value: 1e6, symbol: "M" },
|
||||
{ value: 1e9, symbol: "B" },
|
||||
];
|
||||
const rx = /\.0+$|(\.[0-9]*[1-9])0+$/;
|
||||
for (var i = si.length - 1; i > 0; i--) {
|
||||
if (num >= si[i].value) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (num / si[i].value).toFixed(digits).replace(rx, "$1") + si[i].symbol;
|
||||
const formatter = Intl.NumberFormat(undefined, { notation: "compact" });
|
||||
return formatter.format(num);
|
||||
},
|
||||
addCommas(num) {
|
||||
num = parseInt(num);
|
||||
|
Loading…
Reference in New Issue
Block a user