lyb-js 1.6.16 → 1.6.17

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @description 数字每三位添加逗号
2
+ * @description 数字每三位添加逗号(不四舍五入)
3
3
  * @param num 需要格式化的数字
4
4
  * @param reserve 保留小数位数
5
5
  * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsNumComma-数字逗号
@@ -1,11 +1,14 @@
1
+ import Decimal from "decimal.js";
1
2
  /**
2
- * @description 数字每三位添加逗号
3
+ * @description 数字每三位添加逗号(不四舍五入)
3
4
  * @param num 需要格式化的数字
4
5
  * @param reserve 保留小数位数
5
6
  * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsNumComma-数字逗号
6
7
  */
7
8
  export const libJsNumComma = (num, reserve = 2) => {
8
- const str = num.toFixed(reserve).toString();
9
- const reg = str.indexOf(".") > -1 ? /(\d)(?=(\d{3})+\.)/g : /(\d)(?=(?:\d{3})+$)/g;
9
+ const decimal = new Decimal(num);
10
+ // 截断小数,不四舍五入
11
+ const str = decimal.toFixed(reserve, Decimal.ROUND_DOWN);
12
+ const reg = str.includes(".") ? /(\d)(?=(\d{3})+\.)/g : /(\d)(?=(?:\d{3})+$)/g;
10
13
  return str.replace(reg, "$1,");
11
14
  };
package/lyb.js CHANGED
@@ -3101,8 +3101,9 @@ ${log3.label}:`, log3.value];
3101
3101
  return m.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2");
3102
3102
  };
3103
3103
  const libJsNumComma = (num, reserve = 2) => {
3104
- const str = num.toFixed(reserve).toString();
3105
- const reg = str.indexOf(".") > -1 ? /(\d)(?=(\d{3})+\.)/g : /(\d)(?=(?:\d{3})+$)/g;
3104
+ const decimal = new Decimal(num);
3105
+ const str = decimal.toFixed(reserve, Decimal.ROUND_DOWN);
3106
+ const reg = str.includes(".") ? /(\d)(?=(\d{3})+\.)/g : /(\d)(?=(?:\d{3})+$)/g;
3106
3107
  return str.replace(reg, "$1,");
3107
3108
  };
3108
3109
  const libJsNumberUnit = (num, units, retain = 0) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lyb-js",
3
- "version": "1.6.16",
3
+ "version": "1.6.17",
4
4
  "description": "自用JS方法库",
5
5
  "license": "ISC",
6
6
  "type": "module",