「Excel VBA」RoundDownで浮動数値を切り下げる

関数
WorksheetFunction.RoundDown(引数1、引数2)
引数1 切り下げる対象の数値を指定します
引数2 切り下げた結果の桁数を指定します
RoundDown は、 数値を 常に丸め込む以外は、Round と同様に動作します。
数値num_digits 0 (ゼロ) より大きい場合、数値は指定された小数点以下桁数に切り捨てされます。
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Sub funA()
Dim nA As Double
nA = 3.5
Debug.Print WorksheetFunction.RoundDown(nA, 0)
Debug.Print "***********"
Dim nB As Double
nB = 8.26
Debug.Print WorksheetFunction.RoundDown(nB, 0)
Debug.Print WorksheetFunction.RoundDown(nB, 1)
Debug.Print "xxxxxxxxxx"
Dim nC As Double
nC = 12.93
Debug.Print WorksheetFunction.RoundDown(nC, 0)
Debug.Print WorksheetFunction.RoundDown(nC, 1)
End Sub
Sub funA() Dim nA As Double nA = 3.5 Debug.Print WorksheetFunction.RoundDown(nA, 0) Debug.Print "***********" Dim nB As Double nB = 8.26 Debug.Print WorksheetFunction.RoundDown(nB, 0) Debug.Print WorksheetFunction.RoundDown(nB, 1) Debug.Print "xxxxxxxxxx" Dim nC As Double nC = 12.93 Debug.Print WorksheetFunction.RoundDown(nC, 0) Debug.Print WorksheetFunction.RoundDown(nC, 1) End Sub
Sub funA()

    Dim nA As Double
    nA = 3.5
    Debug.Print WorksheetFunction.RoundDown(nA, 0)
    
    Debug.Print "***********"
    Dim nB As Double
    nB = 8.26
    Debug.Print WorksheetFunction.RoundDown(nB, 0)
    Debug.Print WorksheetFunction.RoundDown(nB, 1)
    
    Debug.Print "xxxxxxxxxx"
    Dim nC As Double
    nC = 12.93
    Debug.Print WorksheetFunction.RoundDown(nC, 0)
    Debug.Print WorksheetFunction.RoundDown(nC, 1)

End Sub

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
3
***********
8
8.2
xxxxxxxxxx
12
12.9
3 *********** 8 8.2 xxxxxxxxxx 12 12.9
 3 
***********
 8 
 8.2 
xxxxxxxxxx
 12 
 12.9 

 

Excel VBA

Posted by arkgame