First 创立
在Interface栏下的Script目录新建一个Scrip文件,然就命名并修改完成FormatAmount方法的代码


function formatAmount(amount, decimalDigits = 0) {
const amountStr = String(Number(amount).toFixed(decimalDigits))
// 运用正则表达式
const reg = /\B(?=(?:\d{3})+$)/g
// 是否是小数
const isDecimal = amountStr.indexOf('.') > -1
if (isDecimal) {
// 整数部分
const integerPart = amountStr.substring(0, amountStr.indexOf('.'))
// 小数部分
const decimalPart = amountStr.substring(amountStr.length, amountStr.indexOf('.'))
return `${integerPart.replace(reg, ',')}${decimalPart}`
} else {
return amountStr.replace(reg, ',')
}
}
运用
在需求运用到的页面导入Js文件,如图所示

然后在action中便可以运用导入的FormatAmount方法,

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。