解决"ASP显示Access里的小数时丢失小数点前面的0"
昨天一个客户的网站说不显示小数点前面的0.搞了好久都不行.其实是我们想太复杂了.
直接用FormatNumber 就可以解决了
FormatNumber(
expression [,NumDigitsAfterDecimal [,IncludeLeadingDigit [,UseParensForNegativeNumbers [,GroupDigits]]]]
)
具体方法请百度.简单一点的说
formatNumber(num,2,-1)
2;表示两位小数
-1:表示是否显示小数前的数字0
顺便附上网站的说的解决办法:
法1:
在"控制面版"---"区域和语言选项"--"区域选项"---"自定义"---"数字"---"零起始显示"中选择0.xx (没搞定 )
法2:
如果在做了法1之后还不行,就需要在程序里处理:
if DataValue<1 then
if left(DataValue,1)<>"0" then
DataValue="0"&DataValue
end if
end if
--------------------------------------------------------
其实还有种情况可能会同时出现,那就是你填的是1.30,但在asp里只显示1.3,如果必须要显示1.30,可以这样做:
''小数点后不足2位的,自动补0
if len(DataValue)-instr(DataValue,".")<2 then
DataValue=formatNumber(DataValue,2,-1)
end if
综合上面2种问题,整合解决方法:
if int(DataValue)<>DataValue then
''小数点后不足2位的,自动补0
if len(DataValue)-instr(DataValue,".")<2 then
DataValue=formatNumber(DataValue,2,-1)
end if
''小数点前没有0的小数补0
if DataValue<1 then
if left(DataValue,1)<>"0" then
DataValue="0"&DataValue
end if
end if
end if
(这个也没搞定.不知道是我太笨了还是确实不太好使 )
最新评论
真是很精彩
第一页打开可以...
我按你的方法去...
Yes, probably so it ...
好,学习了。
不懂恋爱鱼儿!...
实用.我喜欢
多谢.一次性解决...
很好,收藏了
删除后不能发表...