asp以千分位格式显示数字

这篇博客介绍了如何在ASP中将数值格式化为千分位格式,通过自定义函数comma,可以轻松将数字如1234567890转化为1,234,567,890的显示方式。" 83751170,7379142,解决ROS依赖错误与安装问题,"['ROS', 'Ubuntu', '软件安装', '依赖管理', '系统故障排除']

很多时候我在处理数值的时候需要把数值变成千分位的格式,即每三个数加一个",",下面是ASP格式化数值的函数。

< % 
function comma(str) 
'判断是否为数值
if not(isnumeric(str)) or str = 0 then 
result = 0 
'判断数值长度
elseif len(fix(str)) < 4 then 
result = str 
else 
pos = instr(1,str,".") 
'判断是否有小数点
if pos > 0 then 
dec = mid(str,pos) 
end if 
'格式化字符串并反向
res = strreverse(fix(str)) 
loopcount = 1 
'依次加上,
while loopcount < = len(res)
tempresult = tempresult + mid(res,loopcount,3) 
loopcount = loopcount + 3 
if loopcount <= len(res) then 
tempresult = tempresult + "," 
end if 
wend 
result = strreverse(tempresult) + dec 
end if
'输出结果 
comma = result 
end function 
%>

使用的时候只需要用把数值放在comma函数里面就好了。

a=1234567890
response.write comma(a)

输出来的结果是:1,234,567,890

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值