uni_modules/t-uvue-ui/libs/index.uts:165:15
export function priceFormat(price : string, decimals : number = 0, thousandsSeparator : string = ',', decimalPoint : string = '¥') : string {
try {
const num : string = price.replace(/[^0-9+-Ee.]/g, '')
const n : string = isFinite(parseFloat(num)) ? num : '0'
const arr : Array<string> = n.split('.')
const p : string = arr[0]
let par : Array<string> = [];
for (let i : Int = p.length; i > 0; i -= 3) {
let start : Int = i - 3
const item : string = p.substring(start, i)
par.unshift(item);
}
let pjo : string = par.join(thousandsSeparator)
if (decimals > 0) {
let angle : string = ''
if (arr.length > 1) {
angle = arr[1].substring(0, decimals.toInt())
}
let anglen = angle.length
if (anglen < decimals) {
let angplac : string = ''
for (let i : number = 0; i < decimals - anglen; i++) {
angplac += '0'
}
angle += angplac
}
pjo += `.${angle}`
}
return `${decimalPoint}${pjo}`
} catch (e) {
console.log(e)
return price
}
}
其中的
for (let i : Int = p.length; i > 0; i -= 3) {
let start : Int = i - 3
const item : string = p.substring(start, i)
par.unshift(item);
}
这里会报错 ,要把 Int 改成 number
1 个回复
TuiPlus - 无介绍
早期版本number会报错,后面官方修复了