@akadenia/helpers 1.6.0 → 1.7.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/README.MD +9 -2
- package/dist/text.js +2 -2
- package/package.json +1 -1
package/README.MD
CHANGED
|
@@ -347,14 +347,21 @@ Arguments
|
|
|
347
347
|
|
|
348
348
|
## `TextHelpers.abbreviateNumber(number)`
|
|
349
349
|
|
|
350
|
-
|
|
351
|
-
Returns the string representation of the abbreviated number
|
|
350
|
+
Returns the string representation of the abbreviated number, rounded to two decimal places.
|
|
352
351
|
|
|
353
352
|
Arguments
|
|
354
353
|
|Name|Type|Required|Description|
|
|
355
354
|
|--|--|--|--|
|
|
356
355
|
|`number`|`number`|`true`|The number to be abbreviated|
|
|
357
356
|
|
|
357
|
+
Examples
|
|
358
|
+
- Numbers below 1,000 are displayed without abbreviation
|
|
359
|
+
- Numbers between 1,000 and 1,000,000 are displayed in thousands (e.g. 1.23K)
|
|
360
|
+
- Numbers between 1,000,000 and 1,000,000,000 are displayed in millions (e.g. 1.23M)
|
|
361
|
+
- Numbers above 1,000,000,000 are displayed in billions (e.g. 1.23B)
|
|
362
|
+
|
|
363
|
+
Note: If the input `number` is null or undefined, the function returns null.
|
|
364
|
+
|
|
358
365
|
# ObjectHelpers
|
|
359
366
|
|
|
360
367
|
Import the ObjectHelpers utility.
|
package/dist/text.js
CHANGED
|
@@ -302,14 +302,14 @@ const abbreviateNumber = (number) => {
|
|
|
302
302
|
const abbreviations = [
|
|
303
303
|
{ value: 1e9, symbol: "B" },
|
|
304
304
|
{ value: 1e6, symbol: "M" },
|
|
305
|
-
{ value: 1e3, symbol: "
|
|
305
|
+
{ value: 1e3, symbol: "K" },
|
|
306
306
|
];
|
|
307
307
|
if (!number || isNaN(number))
|
|
308
308
|
return null;
|
|
309
309
|
const abbreviated = abbreviations.find(({ value }) => Math.abs(number) >= value);
|
|
310
310
|
if (abbreviated) {
|
|
311
311
|
const { value, symbol } = abbreviated;
|
|
312
|
-
return (number / value).toFixed(
|
|
312
|
+
return (number / value).toFixed(2).replace(/\.00$/, "") + symbol;
|
|
313
313
|
}
|
|
314
314
|
return number.toString();
|
|
315
315
|
};
|