为什么ROUND(12.5)=12,而不是13,但round(13.5)=14,总是往偶数靠呢,这还叫四舍五入啊?

解决方案 »

  1.   

    用format函数吧
    format(13.5,"############")=14
    format(12.5,"############")=13
      

  2.   

    我也试过,但在WIN2000中可以,在XP中还是原样
      

  3.   

    重新写个Round函数吧,很简单的。
      

  4.   

    用format算了.
    这个round是比较挫.
      

  5.   

    MSDN中对四舍五入已经解释了,不要大惊小怪
      

  6.   

    帮我写一个四舍五入函数吧,谢谢了!
    =======================
    x=int(x+0.5)
      

  7.   

    试试这个:
    Private Function tonum(kk!) As Integer
    Dim i!, j As Integer
    i = Abs(kk - Round(kk))
    If i >= 0.5 Then
    j = Fix(kk) + 1
    Else
    j = Fix(kk)
    End If
    tomnum = j
    End Function
      

  8.   

    Private Function myformat(num As Single, i As Integer) As Single
    Dim str As String, j As Integer
    str = "############"
    If i = 1 Then
    str = str & ".0"
    End If
    If i > 1 Then
    str = str & ".0"
    For j = 2 To i
    str = str & "0"
    Next j
    End If
    myformat = Format(num, str)
    End FunctionPrivate Sub Command1_Click()
    Dim x As Single
    x = 12.2535
    Debug.Print myformat(x, 1)
    Debug.Print myformat(x, 3)
    End Sub
    result:
    12.3
    12.254
      

  9.   

    Private Function myRound(ByVal val As Double, p As Integer) As Double
        myRound = Format(val, "." & String(p, "#"))
    End Function
      

  10.   

    ROUND 就是这么定义的。简单方法:int(x + 0.5)
      

  11.   

    Private Function myRound(ByVal val As Double, p As Integer) As Double
        myRound = Int(val * 10# ^ p + 0.5) / (10# ^ p)
    End Function    Debug.Print myRound(2.54555, 0)
        Debug.Print myRound(2.54555, 1)
        Debug.Print myRound(2.55555, 2)
        Debug.Print myRound(2.55555, 7)
    结果: 3 
     2.5 
     2.56 
     2.55555 
      

  12.   

    四舍六入五成双用of123的int(x + 0.5)方法最好
      

  13.   

    dim n as integer '为保留的小数点位数
    dim x as single  '为操作数
    int(x*10^n+0.5)/10^n
      

  14.   

    四舍五入 的本意是:
    <5 舍掉
    =5 凑偶数
    >5 入上即:4舍6入5凑偶
    例如:
    ROUND(12.5)=12
    ROUND(11.5)=12
    ROUND(12.49999999999)=12
    ROUND(12.50000000001)=13