很多时候我在处理数值的时候需要把数值变成千分位的格式,即每三个数加一个",",下面是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
这篇博客介绍了如何在ASP中将数值格式化为千分位格式,通过自定义函数comma,可以轻松将数字如1234567890转化为1,234,567,890的显示方式。"
83751170,7379142,解决ROS依赖错误与安装问题,"['ROS', 'Ubuntu', '软件安装', '依赖管理', '系统故障排除']

2242

被折叠的 条评论
为什么被折叠?



