socket-function 0.154.0 → 0.155.0
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.
- package/package.json +1 -1
- package/src/formatting/format.ts +21 -2
package/package.json
CHANGED
package/src/formatting/format.ts
CHANGED
|
@@ -132,7 +132,7 @@ export function formatNumber(count: number | undefined, maxAbsoluteValue?: numbe
|
|
|
132
132
|
|
|
133
133
|
maxAbsoluteValue = maxAbsoluteValue ?? Math.abs(count);
|
|
134
134
|
|
|
135
|
-
let maxDecimals =
|
|
135
|
+
let maxDecimals = 3;
|
|
136
136
|
|
|
137
137
|
// NOTE: We don't switch units as soon as we possible can, because...
|
|
138
138
|
// 3.594 vs 3.584 is harder to quickly distinguish compared to 3594 and 3584,
|
|
@@ -146,7 +146,23 @@ export function formatNumber(count: number | undefined, maxAbsoluteValue?: numbe
|
|
|
146
146
|
let divisor = 1;
|
|
147
147
|
let suffix = "";
|
|
148
148
|
let currencyDecimalsNeeded = false;
|
|
149
|
-
if (maxAbsoluteValue <
|
|
149
|
+
if (maxAbsoluteValue < 0.00000001) {
|
|
150
|
+
maxDecimals = 12;
|
|
151
|
+
} else if (maxAbsoluteValue < 0.0000001) {
|
|
152
|
+
maxDecimals = 11;
|
|
153
|
+
} else if (maxAbsoluteValue < 0.000001) {
|
|
154
|
+
maxDecimals = 10;
|
|
155
|
+
} else if (maxAbsoluteValue < 0.00001) {
|
|
156
|
+
maxDecimals = 9;
|
|
157
|
+
} else if (maxAbsoluteValue < 0.0001) {
|
|
158
|
+
maxDecimals = 8;
|
|
159
|
+
} else if (maxAbsoluteValue < 0.001) {
|
|
160
|
+
maxDecimals = 7;
|
|
161
|
+
} else if (maxAbsoluteValue < 0.01) {
|
|
162
|
+
maxDecimals = 6;
|
|
163
|
+
} else if (maxAbsoluteValue < 0.1) {
|
|
164
|
+
maxDecimals = 5;
|
|
165
|
+
} else if (maxAbsoluteValue < 1000 * extraFactor) {
|
|
150
166
|
if (specialCurrency) {
|
|
151
167
|
currencyDecimalsNeeded = true;
|
|
152
168
|
}
|
|
@@ -168,6 +184,9 @@ export function formatNumber(count: number | undefined, maxAbsoluteValue?: numbe
|
|
|
168
184
|
}
|
|
169
185
|
count /= divisor;
|
|
170
186
|
maxAbsoluteValue /= divisor;
|
|
187
|
+
if (noDecimal) {
|
|
188
|
+
maxDecimals = 0;
|
|
189
|
+
}
|
|
171
190
|
|
|
172
191
|
return formatMaxDecimals(count, maxDecimals, maxAbsoluteValue, currencyDecimalsNeeded ? 2 : undefined) + suffix;
|
|
173
192
|
}
|