|
-
May 7th, 2003, 05:41 AM
#1
Thread Starter
Registered User
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.
-
May 7th, 2003, 08:30 AM
#2
Lively Member
I never knew about this, thanks for making me aware of it!
-
May 7th, 2003, 09:53 AM
#3
Frenzied Member
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
-
May 7th, 2003, 10:00 AM
#4
yay gay
try using Math.Flower if i am not in error
\m/  \m/
-
May 7th, 2003, 10:04 AM
#5
Frenzied Member
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
-
May 7th, 2003, 10:19 AM
#6
Lively Member
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.
-
May 9th, 2003, 06:08 AM
#7
Thread Starter
Registered User
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|