微信小程序数据绑定保留小数位数

使用wxs写一个filter过滤函数

WXS

/*wxs*/
var NumberFormat = {
  toFix: function (value, precision) {
    return value.toFixed(precision)
  }
}

module.exports = {
  toFix: NumberFormat.toFix
}

WXML

/*wxml*/
<wxs module="numberFormat" src="../../filters/NumberFormat.wxs"></wxs>

<view>{{numberFormat.toFix(item.price, 2)}}</view>
上一篇 Vue.js国际化插件vue-i18n的使用
下一篇 微信小程序自定义radio和checkbox样式
目录
文章列表
1 Android Activity设置转场动画
Android Activity设置转场动画
2
React Native学习之开源轮播组件react-native-swiper
React Native学习之开源轮播组件react-native-swiper
3
可视化监控工具Grafana安装及使用
可视化监控工具Grafana安装及使用
4
CentOS 7下OpenLDAP编译安装及配置
CentOS 7下OpenLDAP编译安装及配置
5
Spring Boot集成EventBus(Guava方式)
Spring Boot集成EventBus(Guava方式)
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。