- Automatic rounding
If the primary number is odd and decimal numbers> = 0.5, then the rounding up (main numbers plus 1) and if the decimal number <0.5, then the rounding down.
However, if the main number is 0 or even, and decimal numbers> 0.5, then the rounding up and when the decimal number <= 0.5, then the rounding down.
i = CInt (0.4), the result is 0
i = CInt (0.5), the result is 0
i = CInt (0.6), the result 1
i = CInt (1.4), the result 1
i = CInt (1.5), the result is 2
i = CInt (1.6), the result is 2
- Rounding Always Down
i = Int (1.1), the result 1
i = Int (1.5), the result 1
i = Int (1.8), the result 1
- Always rounding to the Top
i =-Int (- (1.1)), the result is 2
i =-Int (- (1.5)), the result is 2
i =-Int (- (1.8)), the result is 2
- Rounding The Specified
So if the decimal number> = limit then the rounding up and when the decimal number <limit then the rounding down.
For example, the prescribed limit is 0.4 code like this:
- Dim Nilai As Double, Hasil As Long
Nilai = 1.4 'bilangan yg akan dibulatkan
Hasil = Int(Nilai) + IIf(CDbl(CStr(Nilai - Int(Nilai))) >= 0.4, 1, 0) 'Batas = 0,4
MsgBox Hasil 'pesan Hasil = 2
0 comments:
Post a Comment