解决"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
(这个也没搞定.不知道是我太笨了还是确实不太好使 )
最新评论
强大!
The purchases I make...
At last! Somonee who...
Good job mkanig it a...
How neat! Is it real...
Unparalleled accurac...
Thanky Thanky for al...
That's an inenguios ...
Holy szhinit, this i...
If you wrote an atri...