Modified numeralFormat.ts to prevent NaNt from appearing

This commit is contained in:
Tesseract1234567890 2021-06-02 16:07:52 -04:00
parent a1e0d40963
commit 8fba3c3fa4

@ -16,6 +16,9 @@ import 'numeral/locales/ru';
/* eslint-disable class-methods-use-this */ /* eslint-disable class-methods-use-this */
const extraFormats = [1e15, 1e18, 1e21, 1e24, 1e27, 1e30];
const extraNotations = ['q', 'Q', 's', 'S', 'o', 'n'];
class NumeralFormatter { class NumeralFormatter {
// Default Locale // Default Locale
defaultLocale = "en"; defaultLocale = "en";
@ -54,8 +57,6 @@ class NumeralFormatter {
formatMoney(n: number): string { formatMoney(n: number): string {
if(numeral.options.currentLocale === "en") { if(numeral.options.currentLocale === "en") {
const extraFormats = [1e15, 1e18, 1e21, 1e24, 1e27, 1e30];
const extraNotations = ['q', 'Q', 's', 'S', 'o', 'n'];
for(let i = 0; i < extraFormats.length; i++) { for(let i = 0; i < extraFormats.length; i++) {
if(extraFormats[i] < n && n <= extraFormats[i]*1000) { if(extraFormats[i] < n && n <= extraFormats[i]*1000) {
return '$'+this.format(n/extraFormats[i], '0.000')+extraNotations[i]; return '$'+this.format(n/extraFormats[i], '0.000')+extraNotations[i];
@ -75,15 +76,51 @@ class NumeralFormatter {
} }
formatExp(n: number): string { formatExp(n: number): string {
return this.format(n, "0.000a"); if(numeral.options.currentLocale === "en") {
for(let i = 0; i < extraFormats.length; i++) {
if(extraFormats[i] < n && n <= extraFormats[i]*1000) {
return this.format(n/extraFormats[i], '0.000')+extraNotations[i];
}
}
}
if(Math.abs(n) < 1000) {
return this.format(n, "0.000");
}
const str = this.format(n, "0.000a");
if(str === "NaNt") return this.format(n, '0.000e+0');
return str;
} }
formatHashes(n: number): string { formatHashes(n: number): string {
return this.format(n, "0.000a"); if(numeral.options.currentLocale === "en") {
for(let i = 0; i < extraFormats.length; i++) {
if(extraFormats[i] < n && n <= extraFormats[i]*1000) {
return this.format(n/extraFormats[i], '0.000')+extraNotations[i];
}
}
}
if(Math.abs(n) < 1000) {
return this.format(n, "0.000");
}
const str = this.format(n, "0.000a");
if(str === "NaNt") return this.format(n, '0.000e+0');
return str;
} }
formatReputation(n: number): string { formatReputation(n: number): string {
return this.format(n, "0.000a"); if(numeral.options.currentLocale === "en") {
for(let i = 0; i < extraFormats.length; i++) {
if(extraFormats[i] < n && n <= extraFormats[i]*1000) {
return this.format(n/extraFormats[i], '0.000')+extraNotations[i];
}
}
}
if(Math.abs(n) < 1000) {
return this.format(n, "0.000");
}
const str = this.format(n, "0.000a");
if(str === "NaNt") return this.format(n, '0.000e+0');
return str;
} }
formatFavor(n: number): string { formatFavor(n: number): string {
@ -104,11 +141,35 @@ class NumeralFormatter {
} }
formatRespect(n: number): string { formatRespect(n: number): string {
return this.format(n, "0.00000a"); if(numeral.options.currentLocale === "en") {
for(let i = 0; i < extraFormats.length; i++) {
if(extraFormats[i] < n && n <= extraFormats[i]*1000) {
return this.format(n/extraFormats[i], '0.00000')+extraNotations[i];
}
}
}
if(Math.abs(n) < 1000) {
return this.format(n, "0.00000");
}
const str = this.format(n, "0.00000a");
if(str === "NaNt") return this.format(n, '0.00000e+0');
return str;
} }
formatWanted(n: number): string { formatWanted(n: number): string {
return this.format(n, "0.00000a"); if(numeral.options.currentLocale === "en") {
for(let i = 0; i < extraFormats.length; i++) {
if(extraFormats[i] < n && n <= extraFormats[i]*1000) {
return this.format(n/extraFormats[i], '0.00000')+extraNotations[i];
}
}
}
if(Math.abs(n) < 1000) {
return this.format(n, "0.00000");
}
const str = this.format(n, "0.00000a");
if(str === "NaNt") return this.format(n, '0.00000e+0');
return str;
} }
formatMultiplier(n: number): string { formatMultiplier(n: number): string {
@ -136,14 +197,34 @@ class NumeralFormatter {
} }
formatShares(n: number): string { formatShares(n: number): string {
if (n < 1000) { if(numeral.options.currentLocale === "en") {
return this.format(n, "0"); for(let i = 0; i < extraFormats.length; i++) {
if(extraFormats[i] < n && n <= extraFormats[i]*1000) {
return this.format(n/extraFormats[i], '0.000')+extraNotations[i];
}
}
} }
return this.format(n, "0.000a"); if(Math.abs(n) < 1000) {
} return this.format(n, "0.000");
}
const str = this.format(n, "0.000a");
if(str === "NaNt") return this.format(n, '0.000e+0');
return str; }
formatInfiltrationSecurity(n: number): string { formatInfiltrationSecurity(n: number): string {
return this.format(n, "0.000a"); if(numeral.options.currentLocale === "en") {
for(let i = 0; i < extraFormats.length; i++) {
if(extraFormats[i] < n && n <= extraFormats[i]*1000) {
return this.format(n/extraFormats[i], '0.000')+extraNotations[i];
}
}
}
if(Math.abs(n) < 1000) {
return this.format(n, "0.000");
}
const str = this.format(n, "0.000a");
if(str === "NaNt") return this.format(n, '0.000e+0');
return str;
} }
formatThreads(n: number): string { formatThreads(n: number): string {