Home » » Round Decimal Numbers

Round Decimal Numbers

Many ways in VB to round a number / decimal numbers into integers. If you do not understand, here's a brief explanation:
  •      Automatic rounding
     Rounding is done automatically depending on the number is.
     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
     Rounding is done is always down any decimal digit. In other words, would eliminate the decimal numbers.
     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
     Rounding is done is always up regardless of decimal numbers.
     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
     Rounding is done according to a predetermined limit.
     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
Jika Anda menyukai Artikel di blog ini, Silahkan klik disini untuk berlangganan gratis via email, dengan begitu Anda akan mendapat kiriman artikel setiap ada artikel yang terbit di Creating Website

0 comments:

Post a Comment

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Sanjaya Catur Blogging - All Rights Reserved
Template Modify by Creating Website
Proudly powered by Blogger