Results 1 to 7 of 7

Thread: Rounding a number

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2000
    Location
    Brooklyn Ohio
    Posts
    26
    I would like to round off a number to 4 decimal places

    13.58386104
    What I'm looking for is 13.5839

    Thank you

  2. #2
    Fanatic Member
    Join Date
    Sep 2000
    Location
    UK.
    Posts
    728

    Wink Rounding.

    Use the VB Round function.

    Code:
    MsgBox Round(13.58386104, 4)
    Hope this helps!

    Later
    Digital-X-Treme
    Contact me on MSN Messenger: digital_x_treme@hotmail.com

    [VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
    / (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]

  3. #3
    New Member
    Join Date
    Aug 2000
    Location
    Colombia
    Posts
    10
    Use the Format function too

    Format(13.4582,"0.00") = 13.46

  4. #4
    Guest

    ROUND

    when i used round it didn't seem to round correctly with more than 2 decimal places..

  5. #5
    Fanatic Member
    Join Date
    Sep 2000
    Location
    UK.
    Posts
    728

    Question Possible Solution?

    nzer, check to make sure you are using the correct data types. For example, if you store the result of Round() in an integer or long, it will only store the number up to the decimal point. If you store the result of Round() in a Double, then it works fine.

    Code:
    'Rounds well. Produces 3.21212
    Dim x As Double
    x = Round(3.21212321334341, 5)
    MsgBox x
    
    
    'Doesn't work. Produces 3
    Dim x As Integer
    x = Round(3.21212321334341, 5)
    MsgBox x
    Hope this helps!

    Later
    Digital-X-Treme
    Contact me on MSN Messenger: digital_x_treme@hotmail.com

    [VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
    / (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]

  6. #6
    Guest

    ahh i see

    i had my value set to integer... thats probably why!
    thanks

  7. #7
    New Member
    Join Date
    May 2000
    Location
    Midlands UK
    Posts
    6
    Where A = 13.58386104 then

    A = (Int( A * 10000 + .5)) / 10000

    A = 13.5839

    Additionally if you wanted to round to the nearest lowest 3 DP. then

    A = (Int( A * 1000 )) / 1000

    A = 13.583

    Or Nearest Highest Quarter (For those who work with Imperial dimensions in engineering.)

    A = (Int( A * 4 + .9999999 )) / 4

    A = 13.750


    You could quite easily convert all this into routines. Hope it helps.
    Brian Crutchley UK

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width