Results 1 to 7 of 7

Thread: Problem with rounding a number! [Resolved]

  1. #1

    Thread Starter
    Registered User
    Join Date
    Apr 2003
    Location
    Klang, Selangor, Malaysia
    Posts
    163

    Question Problem with rounding a number! [Resolved]

    In real life, When we try to round a number, let say 3.825, up to 2 decimal points,
    the answer is 3.83, right?

    Unfortunately in VB .NET, the "Math.Round" method & "Decimal.Round" method,
    round number like this (Read the remarks I quote from the Help file ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfSystemDecimalClassRoundTopic.htm):

    "When d is exactly halfway between two rounded values, the result is the rounded value that has an even digit in the far right decimal position. For example, when rounded to two decimals, the value 2.345 becomes 2.34 and the value 2.355 becomes 2.36. This process is known as rounding toward even, or rounding to nearest."

    So my question is how can be avoid this type of rounding method. Is there anyway or any method that enables us to round number like in the real life?

    Please guide. Thank you.
    Last edited by albertlse; Aug 21st, 2003 at 08:30 PM.

  2. #2
    Lively Member
    Join Date
    Feb 2003
    Location
    UK
    Posts
    95
    I never knew about this, thanks for making me aware of it!

  3. #3
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    What you mean by real life? Rounding toward even is the default rounding standard of IEEE.
    '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

  4. #4
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    try using Math.Flower if i am not in error
    \m/\m/

  5. #5
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Thats Math.Floor and returns the largest whole number less than or equal to the desired value. And Math.Celing is oposite.
    '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

  6. #6
    Lively Member
    Join Date
    Jan 2001
    Posts
    79
    I have not tried this but if I am not mistaken I had a similar issue in the past and I used to add .005 and the cut instead of round.

    Unfortunalty sometimes you have to find a work around.

  7. #7

    Thread Starter
    Registered User
    Join Date
    Apr 2003
    Location
    Klang, Selangor, Malaysia
    Posts
    163

    Unhappy

    TonySaliba, how you overcome / solve this problem? Do you mind telling me / share your source code with me? I'll appreciate it. Please. Thank you.

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