1.新开一个页面,叫addmul.wxs,写入下面的函数等内容
var filters = {
//百分比数据
Percentage: function(number1,number2){
return (Math.round(number1/(number2)*10000)/100.00+"%")
}
}
module.exports = {
Percentage: filters.Percentage
}
2.在需要处理数据的地方引入
3.如果有循环的数据直接将数据带入
<view class="tr" wx:for="{{YWHHXRS}}" wx:key="index">
<view class="td" style="width:150rpx">{{item.XM}}</view>
<view class="td">{{item.XB == 1? '男': '女'}}</view>
<view class="td">{{item.AGE}}</view>
<view class="td">{{item.ZZMM}}</view>
<view class="td">{{item.LZFH}}</view>
<view class="td">{{item.TPZS}}</view>
<view class="td">{{filters.Percentage(item.TPZS,item.TPRS)}}</view>
<view class="td">{{item.TPMJ}}</view>
<view class="td">{{filters.Percentage(item.TPMJ,item.TPMJ)}}</view>
</view>
其中filters.Percentage(item.TPZS,data.TPRS)具体是指:
执行函数 Percentage(69,99)
结果会在页面中返回69.7%