Private Sub Form_Load() MsgBox Round(0.125, 2), Title:="Round 0.125 ; 2" MsgBox ReyRound(0.125, 2), Title:="ReyRound 0.125 ; 2" MsgBox Round(0.135, 2), Title:="Round 0.135 ; 2" MsgBox ReyRound(0.135, 2), Title:="ReyRound 0.135 ; 2" End Sub Public Function ReyRound(Value As Double, Size As Integer) As Double Dim Factor As Long Factor = Val("1" & String(Size, "0")) ReyRound = Val(Value * Factor) / Factor End Function
Public Function ReyRound(Value As Double, Size As Integer) As Double Dim Factor As Long Factor = Val("1" & String(Size, "0")) Dim Unit As Double Unit = Val("0." & String(Size - 1, "0") & "1") Dim Resultat As Double Resultat = (Val(Value * Factor) / Factor) If CDbl(Resultat & "5") <= Value Then ReyRound = Resultat + Unit Else ReyRound = Resultat End If End Function Private Sub Form_Load() MsgBox Round(0.125, 2), Title:="Round 0.125 ; 2" MsgBox ReyRound(0.125, 2), Title:="ReyRound 0.125 ; 2" MsgBox Round(0.124, 2), Title:="Round 0.124 ; 2" MsgBox ReyRound(0.124, 2), Title:="ReyRound 0.124 ; 2" End End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question