🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

complex-utils

Package Overview
Dependencies
Maintainers
1
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

complex-utils - npm Package Compare versions

Comparing version
2.10.3
to
2.10.4
+3
-0
history.md

@@ -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