ورود

View Full Version : چند مثال روش استفاده از دستور Round به جای Rnd



www.pc3enter.tk
جمعه 20 فروردین 1395, 16:06 عصر
round(YourNumber + 0.05, 1)



Private Function RoundMe(ByRef sngNo As Single) As Single
Dim a

a = sngNo * 10

If a <> Int(a) Then
RoundMe = Round(sngNo + 0.05, 1)
Else
RoundMe = sngNo
End If
End Function





Dim i As Single
i = InputBox("input number")
MsgBox -Int(--Int(-i * 100) / 10) / 10




Sub Demo()
Dim MyVal As Double, Precision As Integer
MyVal = CDbl(InputBox("Value to Round Up"))
Precision = CInt(InputBox("Round up Precision"))
MsgBox Roundup(MyVal, Precision)
End Sub

Function Roundup(MyVal As Double, Precision As Integer) As Single
If Int(MyVal * 10 ^ Precision) = (MyVal * 10 ^ Precision) Then
Roundup = MyVal
Else
Roundup = -(Int(-MyVal * 10 ^ Precision) / 10 ^ Precision)
End If
End Function