complex-utils
Advanced tools
+3
-0
@@ -0,1 +1,4 @@ | ||
| ### 2.10.4 | ||
| - fix: 修正 `parseNum` 处理小数时可能存在的浮点数问题。 | ||
| ### 2.10.3 | ||
@@ -2,0 +5,0 @@ - fix: 修正 `getRandomInList` 调用 `getRandomNum` 生成随机数时未正确传递end的BUG。 |
+1
-1
| { | ||
| "name": "complex-utils", | ||
| "version": "2.10.3", | ||
| "version": "2.10.4", | ||
| "description": "a complex utils", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -12,7 +12,10 @@ | ||
| } | ||
| const integerPart = Math.trunc(num) | ||
| const decimalPart = Number((num - integerPart).toPrecision(15)) | ||
| return [integerPart, decimalPart] | ||
| // 将数字转换为字符串,避免浮点数精度问题 | ||
| const numStr = num.toString() | ||
| const [integerStr, decimalStr] = numStr.split('.') | ||
| const integer = parseInt(integerStr) || 0 | ||
| const decimal = decimalStr ? Number('0.' + decimalStr) : 0 | ||
| return [integer, num >= 0 ? decimal : -decimal] | ||
| } | ||
| export default parseNum |
121406
0.21%3231
0.09%