解决access中round函数不能正确四舍五入的问题 (备忘)

来源:互联网 发布:手机淘宝5.4.3 编辑:程序博客网 时间:2024/04/17 04:12
Function round(x As Double, Y As Integer) As Double'四舍五入函数'将数字转化为字符串,判断是否大于4,截掉多余部分Dim douShuZhi As DoubleDim strShuZhi As StringDim b As StringDim tt As IntegerDim strZiFu As StringDim longshuzhi As Long'当数据以科学计数法表示时,换成以下格式x = Format(x, "0.00000000")strShuZhi = str(x)b = strShuZhitt = 1'判断小数点在字符串中的位置Do While Not Left(b, 1) = "." And Len(b) <> 0    b = Right(b, Len(b) - 1)    tt = tt + 1 Loop '取出需要判断数字If Len(strShuZhi) <> 0 ThenstrZiFu = Mid(strShuZhi, Y + tt + 1, 1)Else    round = x    Exit Function    End If'判断是否大于4'区分是否正负数————Sgn(X)If Val(strZiFu) > 4 Then    round = Val(Left(strShuZhi, tt + Y)) + Sgn(x) * (1 / (10 ^ Y))Else    round = Val(Left(strShuZhi, tt + Y))End IfEnd Function