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.
- package/Formatter/LibJsNumComma.d.ts +1 -1
- package/Formatter/LibJsNumComma.js +6 -3
- package/lyb.js +3 -2
- package/package.json +1 -1
|
@@ -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
|
|
9
|
-
|
|
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
|
|
3105
|
-
const
|
|
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) => {
|