我在我的sql server中使用报告一个简单的vbscript命令来格式化一些数字字段:
FormatNumber(value,,-1,0,-1)
对我来说重要的是第二个参数 NumDigAfterDec 设置为默认值,意思是 "计算机的区域设置被使用" (http://www.w3schools.com/vbscript/func_formatnumber.asp)。这正是我的喜好。但是当当前数字在小数点后有更多位数时,它是四舍五入的。在这种情况下,我希望看到所有地方。
e.g。对于小数点后的两个位置,我想:
0 0.00
90.7 90.70
1.2345 1.2345 (instead of 1.23)
如果不在我的报告中编写代码,这可能吗?
答案 0 :(得分:1)
如果我理解正确,你想要一个条件,说明十进制的长度是否大于2位,然后显示完整的十进制数,否则2位小数?
一种简单的方法是:
Dim value : value = "100.54367"
Dim GetDecCount : GetDecCount = Len(Mid(Value, instr(value, ".")+1, len(value)))
if GetDecCount>2 then
msgbox "This number exceeds the regional decimal points of 2, with a length of " & GetDecCount & " decimal points."
else
FormatNumber(value,,-1,0,-1)
end if
答案 1 :(得分:1)
尝试这样的事情:
Set re = New RegExp
re.Pattern = ".\d{3,}$"
if re.Test(value) Then
fnum = CStr(value)
Else
fnum = FormatNumber(value, , -1, 0, -1)
End If