intelica-library-ui 0.1.217 → 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,32 +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
181
|
const suffixes = ["", "K", "M", "B", "T"];
|
|
191
182
|
const factor = Math.pow(10, decimalPlaces);
|
|
192
183
|
const rounded = Math.round(value * factor) / factor;
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
return rounded.toFixed(decimalPlaces);
|
|
196
|
-
}
|
|
184
|
+
let tier = Math.floor(Math.log10(Math.abs(rounded || 1)) / 3);
|
|
185
|
+
tier = Math.max(0, Math.min(tier, suffixes.length - 1));
|
|
197
186
|
const scaled = rounded / Math.pow(10, tier * 3);
|
|
198
|
-
return
|
|
187
|
+
return this.formatWithThousandSeparators(scaled, decimalPlaces) + suffixes[tier];
|
|
199
188
|
}
|
|
200
189
|
formatWithThousandSeparators(value, decimalPlaces) {
|
|
201
190
|
return new Intl.NumberFormat("en-US", {
|