微信小程序千分位

1. 新建一个wxs文件
//逢三位转逗号

var threeNum={ add_comma_toThousands:function(num){ 
var num=(num || 0).toString();
var result='';
while(num.length>3){
result=','+num.slice(-3)+result;
num=num.slice(0,num.length-3);
}
if(num){
result=num+result;
}
return result;
}
}

  


2. wxml文件中导入

<wxs src="../../utils/tool.wxs" module="tool" />

 


分别是函数外部方法名和路径

3. 使用

<view>金额:{{threeNum.add_comma_toThousands(888888)}}</view>

  


显示的结果为:888,888 

猜你喜欢

转载自www.cnblogs.com/bosslandy/p/9922181.html