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

wft-utils

Package Overview
Dependencies
Maintainers
1
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wft-utils - npm Package Compare versions

Comparing version
1.52.0
to
1.52.1
+1
-1
package.json
{
"name": "wft-utils",
"version": "1.52.0",
"version": "1.52.1",
"description": "The commonly used tool functions in daily development",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -1075,21 +1075,17 @@ /**

*/
export function numberToCurrencyNo(value) {
export function numberToCurrencyNo(value, decimals = 2) {
if (!value) return '0'
if (value === '--') return '--'
value = value - 0
// 将数值截取,保留0位小数
value = value.toFixed(0)
// 获取整数部分
const intPart = Math.trunc(value)
// 整数部分处理,增加,
const intPartFormat = intPart.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,')
// 预定义小数部分
let floatPart = ''
// 将数值截取为小数部分和整数部分
const valueArray = value.toString().split('.')
if (valueArray.length === 2) { // 有小数部分
floatPart = valueArray[1].toString() // 取得小数部分
return intPartFormat + '.' + floatPart
}
return intPartFormat + floatPart
const num = Number(value)
if (isNaN(num)) return '0'
const fixedNum = num.toFixed(decimals)
const [intStr, floatStr] = fixedNum.split('.')
const intFormat = intStr.replace(/(\d)(?=(?:\d{3})+$)/g, '$1,')
if (!floatStr) return intFormat
// 去掉小数末尾无用的 0
const trimFloat = floatStr.replace(/0+$/, '')
return trimFloat ? `${intFormat}.${trimFloat}` : intFormat
}

@@ -1096,0 +1092,0 @@