Results 1 to 11 of 11

Thread: rounding to 2dp

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    509

    rounding to 2dp

    there is a thread on the forums that is for vb6. i tried it and it doesnt work.

    How is it possible to round to 2d.p?

    i tried this:

    Label8.Text = round(span.TotalMinutes * lblrate.Text)

    the round word is highligted meaning its wrong

    can anyone help?

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    This for VB.NET !

    VB Code:
    1. Math.Round(decimal value)

  3. #3
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Try Math.Round

  4. #4
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    Use Math.Round.

    Many of the functions found in VB6 is still available, but have been placed under different namespaces.

    So all mathematical functions are found under the namespace Math.

    Hope that made any sence...

    Edit. Damn Mike. You made it just before I did...
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    509
    math.round only gives me a whole value. Which means it rounds it up to the nearest whole value.

    How is it possible to round it up to 2 decimal places?

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    509
    its ok i worked it out

  7. #7
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Side note.

    Although I guess I understand the "rules" of rounding, logically this does not make sense to me:

    VB Code:
    1. MsgBox(Math.Round(42.5, 0)) ' Displays "42"
    2.         MsgBox(Math.Round(43.5, 0)) ' Displays "44"
    But that's the design.

  8. #8
    Member
    Join Date
    Dec 2003
    Posts
    43
    Also there is math.ceiling which will round to the highest integer
    ex. 12.1 would return 13
    another cool one is math.floor
    ex. 12.98 would return 12

  9. #9
    Member
    Join Date
    Dec 2003
    Posts
    43
    Originally posted by Mike Hildner
    Side note.

    Although I guess I understand the "rules" of rounding, logically this does not make sense to me:

    VB Code:
    1. MsgBox(Math.Round(42.5, 0)) ' Displays "42"
    2.         MsgBox(Math.Round(43.5, 0)) ' Displays "44"
    But that's the design.
    also your msgbox is legacy code for message box
    it should be messagebox.show(and in here goes your stuff)
    it is a overloaded procedure so its much more versatile then
    msgbox.

  10. #10
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Originally posted by Mike Hildner
    Side note.

    Although I guess I understand the "rules" of rounding, logically this does not make sense to me:

    VB Code:
    1. MsgBox(Math.Round(42.5, 0)) ' Displays "42"
    2.         MsgBox(Math.Round(43.5, 0)) ' Displays "44"
    But that's the design.
    Isn't that the rule of 'rounding towards even'? That's an IEEE standard.
    Last edited by Lunatic3; Jan 1st, 2004 at 10:46 PM.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  11. #11
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Yes it is the rule. Just thought I'd point it out because it can make for some "gotchas" if you're not aware of it.

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