Is there any inbuilt function to convert a decimal number to integer in vb ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • veenaps
    New Member
    • Sep 2010
    • 2

    #1

    Is there any inbuilt function to convert a decimal number to integer in vb ?

    Supposing i need to convert 12.3 to 12 or 13 depending on some criterion, do i need to get the decimal part and multiply by 10 or there is an inbuilt function to do the conversion ?
  • Guido Geurs
    Recognized Expert Contributor
    • Oct 2009
    • 767

    #2
    Int(number) gives the integer of a number (see help VB).
    But there are also other functions with an integer as result but with different outcome.

    There is Int(number), Fix(number) and Round(expressio n [,numdecimalplac es])

    Comment

    • veenaps
      New Member
      • Sep 2010
      • 2

      #3
      dec_int_convers ion

      Hi,
      Thanks for the reply. I know about int(number) which gives rounddown operation result. I wanted to know if there is any roundup function as such.

      Comment

      • Guido Geurs
        Recognized Expert Contributor
        • Oct 2009
        • 767

        #4
        There is also:

        When the fractional part is exactly 0.5, CInt and CLng always round it to the nearest even number. For example, 0.5 rounds to 0, and 1.5 rounds to 2. CInt and CLng differ from the Fix and Int functions, which truncate, rather than round, the fractional part of a number. Also, Fix and Int always return a value of the same type as is passed in.

        Or You can use:

        Code:
           If Val(Text1) > Int(Val(Text1)) Then
              Text_roundup = Int(Val(Text1)) + 1
           Else
              Text_roundup = Int(Val(Text1))
           End If

        Comment

        Working...