update formatMoney and format_coin
This commit is contained in:
parent
a6cada784f
commit
9d766b30a8
22
unitool.js
22
unitool.js
@ -492,8 +492,26 @@ export default {
|
|||||||
// #endif
|
// #endif
|
||||||
},
|
},
|
||||||
|
|
||||||
formatMoney (value, precision = 2) {
|
formatMoney (amount, { precision = 2 } = {}) {
|
||||||
return Number(value || 0).toFixed(precision) // Number(undefined)===NaN
|
if (Number.isNaN(parseInt(amount))) {
|
||||||
|
// parseInt(NaN/undefined/false/null/'') 都返回 NaN,而 Number(false/null/'')===0,因此用 parseInt 来过滤无效输入。
|
||||||
|
// 或者可以 if (!['number', 'string'].includes(typeof amount) && [NaN, undefined, false, null, ''].includes(amount))
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
// Number(amount).toFixed(precision) // toFixed 虽然方便,但是会自动四舍五入。
|
||||||
|
return `${parseInt(Number(amount) * Math.pow(10, precision)) / Math.pow(10, precision)}`
|
||||||
|
},
|
||||||
|
|
||||||
|
format_coin (amount, { coin = wo.envar.KEYNAME, precision = 8 } = {}) {
|
||||||
|
if (Number.isNaN(parseInt(amount))) {
|
||||||
|
// parseInt(NaN/undefined/false/null/'') 都返回 NaN,而 Number(false/null/'')===0,因此用 parseInt 来过滤无效输入。
|
||||||
|
// 或者可以 if (!['number', 'string'].includes(typeof amount) && [NaN, undefined, false, null, ''].includes(amount))
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
if (coin === wo.envar.KEYNAME && wo.envarRemote?.pexPrecision) {
|
||||||
|
precision = wo.envarRemote?.pexPrecision // precision 要有默认值,以防无法连接后台时,这个方法会导致 part-header.vue 出错。
|
||||||
|
}
|
||||||
|
return `${parseInt(Number(amount) * Math.pow(10, precision)) / Math.pow(10, precision)}`
|
||||||
},
|
},
|
||||||
|
|
||||||
formatPercent (value, precision = 2) {
|
formatPercent (value, precision = 2) {
|
||||||
|
Loading…
Reference in New Issue
Block a user