vbscript VBA函数以传统方式舍入以5结尾的数字,而不是“舍入到偶数”逻辑。不幸的是,这是显着的

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vbscript VBA函数以传统方式舍入以5结尾的数字,而不是“舍入到偶数”逻辑。不幸的是,这是显着的相关的知识,希望对你有一定的参考价值。

Function TradRound(val As Double, Optional places As Integer) As Double
    
    Dim divisor As Double
    Dim val2 As Double

    If IsMissing(places) Then places = 0

    divisor = 10 ^ places
    val2 = val * divisor - Int(val * divisor)

    If val2 = 0.5 Then
        TradRound = (Int(val * divisor) + 1) / divisor
    Else
        TradRound = Round(val, places)
    End If
    
End Function

以上是关于vbscript VBA函数以传统方式舍入以5结尾的数字,而不是“舍入到偶数”逻辑。不幸的是,这是显着的的主要内容,如果未能解决你的问题,请参考以下文章