zet-lib 1.5.1 → 1.5.2
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/lib/Util.js +15 -9
- package/package.json +1 -1
package/lib/Util.js
CHANGED
|
@@ -622,16 +622,22 @@ Util.toNumber = function (num) {
|
|
|
622
622
|
};
|
|
623
623
|
|
|
624
624
|
Util.formatNumber = function (num, thousandSeparator = ".") {
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
625
|
+
try {
|
|
626
|
+
const strValue = String(num);
|
|
627
|
+
// Split into integer and decimal parts
|
|
628
|
+
const parts = strValue.split(",");
|
|
629
|
+
// Format integer part with thousand separators
|
|
630
|
+
const integerPart = parts[0].replace(
|
|
631
|
+
/\B(?=(\d{3})+(?!\d))/g,
|
|
632
|
+
thousandSeparator
|
|
632
633
|
);
|
|
633
|
-
|
|
634
|
-
|
|
634
|
+
// If there's a decimal part, add it back
|
|
635
|
+
if (parts.length > 1) {
|
|
636
|
+
return `${integerPart},${parts[1]}`;
|
|
637
|
+
}
|
|
638
|
+
return integerPart;
|
|
639
|
+
} catch (e) {
|
|
640
|
+
console.log(e);
|
|
635
641
|
}
|
|
636
642
|
};
|
|
637
643
|
|