Le funzioni VBA Int e Fix restituiscono una parte intera di un numero.
Int(numero)
Fix(numero)
Utilizzo delle funzioni Int e Fix per convertire diversi tipi di valori numerici, che ti aiutano anche a comprendere meglio la differenza quando hai a che fare con valori negativi:
Sub IntFixExample()
MsgBox Int(1) 'Resi: 1
MsgBox Fix(1) 'Resi: 1
MsgBox Int(-1) 'Rendimenti: -1
MsgBox Fix(-1) 'Rendimenti: -1
MsgBox Int(2.9) 'Resi: 2
MsgBox Fix(2.9) 'Resi: 2
MsgBox Int(-2.9) 'Rendimenti: -3
MsgBox Fix(-2.9) 'Rendimenti: -2
MsgBox Int(4.5) 'Resi: 4
MsgBox Fix(4.5) 'Resi: 4
MsgBox Int(-4.5) 'Rendimenti: -5
MsgBox Fix(-4.5) 'Rendimenti: -4
MsgBox Int(0.424) 'Restituzioni: 0
MsgBox Fix(0.424) 'Restituzioni: 0
MsgBox Int("13") 'Resi: 13
MsgBox Fix("13") 'Resi: 13
MsgBox Int("-4.5") 'Rendimenti: -5
MsgBox Fix("-4.5") 'Rendimenti: -4
MsgBox Int(True) 'Rendimenti: -1
MsgBox Fix(True) 'Rendimenti: -1
MsgBox Int(False) 'Restituzioni: 0
MsgBox Fix(False) 'Restituzioni: 0
End Sub