四舍五入

来源:互联网 发布:c语言打开txt文件代码 编辑:程序博客网 时间:2024/04/20 09:53

    '***********************************************************************************
        '@(f)
        '機能     :整数の第一位に四捨五入します。
        '
        '返値     :intDigitsに等しい精度の数値に四捨五入された数値。
        '
        '引数     :dblValue - 丸め対象の倍精度浮動小数点数
        '              :intDigits - 戻り値の有効桁数の精度
        '
        '機能説明   :指定した精度の数値に四捨五入します。
        '
        '備考     :
        '*********************************************************************************

Public Function ToRound(ByVal dblValue As Double, _
                                            ByVal intDigits As Integer) As Double
            Dim dblCoef As Double = System.Math.Pow(0.1, intDigits)

            If dblValue > 0 Then
                Return System.Math.Floor((dblValue * dblCoef) + 0.5) / dblCoef
            Else
                Return System.Math.Ceiling((dblValue * dblCoef) - 0.5) / dblCoef
            End If
        End Function 

原创粉丝点击