我有一个Visual Basic应用程序需要向下舍入数字,例如2.556会变成2.55而不是2.26。在Visual Basic中舍入数字
我可以用一个函数来使用这个小数点去掉字符超过2右做到这一点:
Dim TheString As String
TheString = 2.556
Dim thelength = Len(TheString)
Dim thedecimal = InStr(TheString, ".", CompareMethod.Text)
Dim Characters = thelength - (thelength - thedecimal - 2)
_2DPRoundedDown = Left(TheString, Characters)
是否有更好的功能来做到这一点?
如果数字为负则无法使用此工作。 – Justin 2009-08-04 16:33:18
有时将您的数字存储为整数或定点(如果您不需要全部浮点数),对定点数执行计算并在显示给用户时对其进行调整是有益的。 – 2009-08-04 16:45:32
@Justin:好点 - 我编辑为负数,以及积极 – 2009-08-04 16:47:21