Die Funktion VBA Round rundet eine Zahl auf die angegebene Anzahl von Dezimalstellen.
Round(number, number_of_decimal_signs)
Verwenden der Funktion Round, um eine Zahl auf zwei Dezimalstellen zu runden:
Sub RoundExample1()
number = 12.3456
round = Round(number, 2)
MsgBox round 'Rückgabe: 12.35
End Sub
Verwenden der Funktion Round zum Runden verschiedener numerischer Werte:
Sub RoundExample2()
MsgBox Round(14.2) 'Rückgabe: 14
MsgBox Round(-14.2) 'Rückgabe: -14
MsgBox Round("14.2") 'Rückgabe: 14
MsgBox Round("-14.2") 'Rückgabe: -14
MsgBox Round(9.5) 'Rückgabe: 10
MsgBox Round(-9.5) 'Rückgabe: -10
MsgBox Round(1.25, 1) 'Rückgabe: 1.2
MsgBox Round(50, 1) 'Rückgabe: 50
MsgBox Round(4532.6351, 2) 'Rückgabe: 4532.64
End Sub