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.
Files changed (2) hide show
  1. package/lib/Util.js +15 -9
  2. 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
- num = num || "";
626
- let sep = "$1" + thousandSeparator;
627
- let numString = num.toString();
628
- if (numString.indexOf(".") > -1) {
629
- let explode = numString.split(".");
630
- return (
631
- explode[0].replace(/(\d)(?=(\d{3})+(?!\d))/g, sep) + "," + explode[1]
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
- } else {
634
- return numString.replace(/(\d)(?=(\d{3})+(?!\d))/g, sep);
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zet-lib",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "description": "zet is a library that part of zet generator.",
5
5
  "engines": {
6
6
  "node": ">=18"