其他分享
首页 > 其他分享> > 金钱保留n位小数

金钱保留n位小数

作者:互联网

1、新建一个wxs文件

var numberUtil = {
     numberFormat: function (value) {
             // var v = parseInt(value)//强转Int,毕竟有可能返回是String类型的数字
             return value.toFixed(2)
     }
}

module.exports = {
     numberFormat: numberUtil.numberFormat//暴露接口调用
}

2、wxml文件中导入

 <wxs module="numberUtil" src="../../utils/util.wxs"></wxs><!--分别是函数外部方法名和路径-->

3、使用

<view>金额:{{numberUtil.numberFormat(123.5678)}}</view>

 

标签:金钱,文件,numberFormat,function,保留,value,numberUtil,var,小数
来源: https://blog.csdn.net/qq_32603969/article/details/104752444