#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2010
    Posts
    104
    Rep Power
    4

    Find rounding functions VB6.0 ?


    I want to find rounding functions. In VB60. The function can be fulfilled in the for example below

    for example:

    794.5 = 795

    843.4 = 843

    245.345 = 245

    I used the function: Round(), Int(), Fix() but not.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    289
    Rep Power
    45
    Based on the numbers you provided, you want to round a single precision number to the nearest whole number. The "Int" function simply truncates the result.
    Code:
    Private Sub cmdRound_Click()
        Text1.Text = Int(Text1.Text + 0.5)
        Text2.Text = Int(Text2.Text + 0.5)
        Text3.Text = Int(Text3.Text + 0.5)
    End Sub
    The same technique can be used for other significant numbers by multiplying or dividing by powers of 10.

    J.A. Coutts
  4. #3

  5. Join Date
    Jul 2013
    Location
    Melbourne
    Posts
    43
    Rep Power
    0
    Originally Posted by couttsj
    Based on the numbers you provided, you want to round a single precision number to the nearest whole number. The "Int" function simply truncates the result.
    Code:
    Private Sub cmdRound_Click()
        Text1.Text = Int(Text1.Text + 0.5)
        Text2.Text = Int(Text2.Text + 0.5)
        Text3.Text = Int(Text3.Text + 0.5)
    End Sub
    The same technique can be used for other significant numbers by multiplying or dividing by powers of 10.

    J.A. Coutts
    Hi Coutts

    apart from multiplying or dividing is their any other formula for this.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    289
    Rep Power
    45
    Originally Posted by PeterSullivan
    Hi Coutts

    apart from multiplying or dividing is their any other formula for this.
    For single or double precision numbers, you can use the Round function to adjust the number of decimal places. There is no function for rounding numbers to the left of the decimal place.

    J.A. Coutts
  8. #5
  9. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,441
    Rep Power
    4539
    I don't know if this kb article will be helpful, but it looks to be a pretty complete discussion of rounding and different types of rounding.

    http://support.microsoft.com/kb/196652
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester

IMN logo majestic logo threadwatch logo seochat tools logo