Merge pull request #984 from Tesseract1234567890/numeralFormat.ts-NanT-removal

Modified numeralFormat.ts to prevent NaNt from appearing
This commit is contained in:
hydroflame 2021-06-06 14:59:03 -04:00 committed by GitHub
commit 4180ceae17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -16,6 +16,10 @@ 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";
@ -48,42 +52,48 @@ class NumeralFormatter {
return this.format(n, "0.000a"); return this.format(n, "0.000a");
} }
formatHp(n: number): string { formatAbsurdNumber(n: number, decimalPlaces = 3): string {
return this.format(n, "0");
}
formatMoney(n: number): string {
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.'+'0'.repeat(decimalPlaces))+extraNotations[i];
}
} }
} }
if(Math.abs(n) < 1000) { if(Math.abs(n) < 1000) {
return this.format(n, "$0.00"); return this.format(n, '0.'+'0'.repeat(decimalPlaces));
} }
const str = this.format(n, "$0.000a"); const str = this.format(n, '0.'+'0'.repeat(decimalPlaces) + 'a');
if(str === "$NaNt") return '$'+this.format(n, '0.000e+0'); if(str === "NaNt") return this.format(n, '0.' + ' '.repeat(decimalPlaces) + 'e+0');
return str; return str;
} }
formatSkill(n: number): string { formatHp(n: number): string {
if(n < 1e6){
return this.format(n, "0,0"); return this.format(n, "0,0");
} }
return this.formatAbsurdNumber(n, 3)
}
formatMoney(n: number): string {
return "$" + this.formatAbsurdNumber(n, 3);
}
formatSkill(n: number): string {
if(n < 1e15){
return this.format(n, "0,0");
}
return this.formatAbsurdNumber(n, 3);
}
formatExp(n: number): string { formatExp(n: number): string {
return this.format(n, "0.000a"); return this.formatAbsurdNumber(n, 3);
} }
formatHashes(n: number): string { formatHashes(n: number): string {
return this.format(n, "0.000a"); return this.formatAbsurdNumber(n, 3);
} }
formatReputation(n: number): string { formatReputation(n: number): string {
return this.format(n, "0.000a"); return this.formatAbsurdNumber(n, 3);
} }
formatFavor(n: number): string { formatFavor(n: number): string {
@ -104,11 +114,11 @@ class NumeralFormatter {
} }
formatRespect(n: number): string { formatRespect(n: number): string {
return this.format(n, "0.00000a"); return this.formatAbsurdNumber(n, 5);
} }
formatWanted(n: number): string { formatWanted(n: number): string {
return this.format(n, "0.00000a"); return this.formatAbsurdNumber(n, 5);
} }
formatMultiplier(n: number): string { formatMultiplier(n: number): string {
@ -139,11 +149,11 @@ class NumeralFormatter {
if (n < 1000) { if (n < 1000) {
return this.format(n, "0"); return this.format(n, "0");
} }
return this.format(n, "0.000a"); return this.formatAbsurdNumber(n, 3);
} }
formatInfiltrationSecurity(n: number): string { formatInfiltrationSecurity(n: number): string {
return this.format(n, "0.000a"); return this.formatAbsurdNumber(n, 3);
} }
formatThreads(n: number): string { formatThreads(n: number): string {