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