intelica-library-ui 0.1.216 → 0.1.218
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -170,36 +170,21 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.1", ngImpor
|
|
|
170
170
|
|
|
171
171
|
class FormatAmountPipe {
|
|
172
172
|
transform(value, shortFormat = false, decimalPlaces = 2) {
|
|
173
|
-
if (value === null || value === undefined)
|
|
173
|
+
if (value === null || value === undefined)
|
|
174
174
|
return "0";
|
|
175
|
-
}
|
|
176
175
|
const numericValue = typeof value === "string" ? parseFloat(value) : value;
|
|
177
|
-
if (isNaN(numericValue))
|
|
176
|
+
if (isNaN(numericValue))
|
|
178
177
|
return "0";
|
|
179
|
-
|
|
180
|
-
let formattedValue;
|
|
181
|
-
if (shortFormat) {
|
|
182
|
-
formattedValue = this.getShortFormat(numericValue, decimalPlaces);
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
formattedValue = this.formatWithThousandSeparators(numericValue, decimalPlaces);
|
|
186
|
-
}
|
|
187
|
-
return formattedValue;
|
|
178
|
+
return shortFormat ? this.getShortFormat(numericValue, decimalPlaces) : this.formatWithThousandSeparators(numericValue, decimalPlaces);
|
|
188
179
|
}
|
|
189
180
|
getShortFormat(value, decimalPlaces) {
|
|
190
|
-
const
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
];
|
|
197
|
-
for (const { limit, suffix } of suffixes) {
|
|
198
|
-
if (absValue >= limit) {
|
|
199
|
-
return (value / limit).toFixed(decimalPlaces) + suffix;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
return value.toFixed(decimalPlaces);
|
|
181
|
+
const suffixes = ["", "K", "M", "B", "T"];
|
|
182
|
+
const factor = Math.pow(10, decimalPlaces);
|
|
183
|
+
const rounded = Math.round(value * factor) / factor;
|
|
184
|
+
let tier = Math.floor(Math.log10(Math.abs(rounded || 1)) / 3);
|
|
185
|
+
tier = Math.max(0, Math.min(tier, suffixes.length - 1));
|
|
186
|
+
const scaled = rounded / Math.pow(10, tier * 3);
|
|
187
|
+
return this.formatWithThousandSeparators(scaled, decimalPlaces) + suffixes[tier];
|
|
203
188
|
}
|
|
204
189
|
formatWithThousandSeparators(value, decimalPlaces) {
|
|
205
190
|
return new Intl.NumberFormat("en-US", {
|