「Excel VBA」Roundで倍精度浮動小数を四捨五入する
関数
WorksheetFunction.Round(引数1、 引数2)
引数1 四捨五入する対象の数値を指定します
引数2 四捨五入した結果の桁数を指定します
数値num_digits 0 (ゼロ) より大きい場合、数値は指定された小数点以下桁数に丸められます。
使用例
Sub funA()
Dim cftA As Double
cftA = 12.5
Debug.Print WorksheetFunction.Round(cftA, 0)
Debug.Print "**********"
Dim cftB As Double
cftB = 13.26
Debug.Print WorksheetFunction.Round(cftB, 0)
Debug.Print WorksheetFunction.Round(cftB, 1)
Debug.Print "---------"
Dim cftC As Double
cftC = 14.82
Debug.Print WorksheetFunction.Round(cftC, 0)
Debug.Print WorksheetFunction.Round(cftC, 1)
End Sub
Sub funA()
Dim cftA As Double
cftA = 12.5
Debug.Print WorksheetFunction.Round(cftA, 0)
Debug.Print "**********"
Dim cftB As Double
cftB = 13.26
Debug.Print WorksheetFunction.Round(cftB, 0)
Debug.Print WorksheetFunction.Round(cftB, 1)
Debug.Print "---------"
Dim cftC As Double
cftC = 14.82
Debug.Print WorksheetFunction.Round(cftC, 0)
Debug.Print WorksheetFunction.Round(cftC, 1)
End Sub
Sub funA() Dim cftA As Double cftA = 12.5 Debug.Print WorksheetFunction.Round(cftA, 0) Debug.Print "**********" Dim cftB As Double cftB = 13.26 Debug.Print WorksheetFunction.Round(cftB, 0) Debug.Print WorksheetFunction.Round(cftB, 1) Debug.Print "---------" Dim cftC As Double cftC = 14.82 Debug.Print WorksheetFunction.Round(cftC, 0) Debug.Print WorksheetFunction.Round(cftC, 1) End Sub
実行結果
13
**********
13
13.3
---------
15
14.8
13
**********
13
13.3
---------
15
14.8
13 ********** 13 13.3 --------- 15 14.8