Office中国论坛/Access中国论坛

标题: ROUND四舍五入函数经常失效,有好的解决方法吗? [打印本页]

作者: jsjdn2004    时间: 2005-6-6 18:51
标题: ROUND四舍五入函数经常失效,有好的解决方法吗?
请帮我看看查询1中的“配件价格”字段,我用了ROUND函数,但显示出来还是有十几位小数,这是为什么?[attach]11021[/attach]


作者: 海狸先生    时间: 2005-6-6 18:52
用这个Public Function MyRound(dblInput As Variant, Optional intDecimals As Integer) As Double

Dim strFormatString As String    '格式化字符串

    If IsNull(dblInput) Then MyRound = 0: Exit Function

       If dblInput <> 0 Then

       If IsNull(intDecimals) Or intdeximals = 0 Then

        MyRound = Val(Format(dblInput, "#"))

        Else

        strFormatString = "#." & String(Nz(intDecimals), "#")

        MyRound = Val(Format(dblInput, strFormatString))

        End If

    Else

        MyRound = 0

    End If

End Function


作者: nxjswt    时间: 2005-9-24 16:16
海狸,谢谢你冽!

应该是


Public Function MyRound(dblInput As Variant, Optional intDecimals As Integer) As Double
Dim strFormatString As String    '格式化字符串
    If IsNull(dblInput) Then MyRound = 0: Exit Function
       If dblInput <> 0 Then
       If IsNull(intDecimals) Or intDecimals = 0 Then
        MyRound = Val(Format(dblInput, "#"))
        Else
        strFormatString = "#." & String(Nz(intDecimals), "#")
        MyRound = Val(Format(dblInput, strFormatString))
        End If
    Else
        MyRound = 0
    End If
End Function




[此贴子已经被作者于2006-6-4 13:56:16编辑过]






欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3