First 创立

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

在outsystem内使用JavaScript封装一个FormatAmount方法

在outsystem内使用JavaScript封装一个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文件,如图所示

在outsystem内使用JavaScript封装一个FormatAmount方法

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

在outsystem内使用JavaScript封装一个FormatAmount方法