asp 格式化价格

来源:百度知道 编辑:UC知道 时间:2024/05/15 18:19:19
如果第一位是小数点则前面补0,变为0.几几,如果为整数则后面补上.00
求一写好的函数~

dim price
price=.2 //以2角钱为例,假设得到的数据是.2
if left(price,1)="." then price="0" & price
if not instr(price,".") then price=price & ".00"
//至此已经可以满足题中的要求,以下为扩展部分,可以不要,建议保留
if instr(price,".") and len(mid(instr(price,".")))=2 then
if len(mid(instr(price,".")))=0 then
price=price & "00"
else
price=price & "0"
end if
end if
//我没有试过,可能会有问题,你自己试试吧