OK I was having rounding problems before and I didn't realize that
their was a third parameter in the round function that would tell it if
it a 5 to round up. I thought adding this would fix the problem but it
didn't. I have VS 2005 and I am using vb.net try rounding the number
4.935 to 2 decimals:
What I am seeing is the following:
Math.Round(4.935, 2, MidpointRounding.AwayFromZero) 'Result is 4.93
Math.Round(4.935, 2, MidpointRounding.ToEven) 'Result is
4.93
Is this a bug? Am I just missing something?
I want 5 to round up which means AwayFromZero should do it right? In
this case even if I did ToEven it should go to 4.94 but it isn't. Is
it best to just abandon the round function in .Net and make my own. I
feel that rounding is such a basic function that I shouldn't have to
make my own function. Is this a floating point problem with .Net?
Right now I don't know if I can trust the round function that is built
in. 3 5304
Is this a bug?
As far as I'm concerned, yes. Check out this similar thread to see an
explaination: http://groups.google.com/group/micro...748c717a6c3a36
Thanks,
Seth Rowe
Altman wrote:
OK I was having rounding problems before and I didn't realize that
their was a third parameter in the round function that would tell it if
it a 5 to round up. I thought adding this would fix the problem but it
didn't. I have VS 2005 and I am using vb.net try rounding the number
4.935 to 2 decimals:
What I am seeing is the following:
Math.Round(4.935, 2, MidpointRounding.AwayFromZero) 'Result is 4.93
Math.Round(4.935, 2, MidpointRounding.ToEven) 'Result is
4.93
Is this a bug? Am I just missing something?
I want 5 to round up which means AwayFromZero should do it right? In
this case even if I did ToEven it should go to 4.94 but it isn't. Is
it best to just abandon the round function in .Net and make my own. I
feel that rounding is such a basic function that I shouldn't have to
make my own function. Is this a floating point problem with .Net?
Right now I don't know if I can trust the round function that is built
in.
So it seems that this problem happens when you use the type double.
Should I just use the decimal type all the time? Is there a benefit of
using decimal over double or vice versa?
rowe_newsgroups wrote:
Is this a bug?
As far as I'm concerned, yes. Check out this similar thread to see an
explaination:
http://groups.google.com/group/micro...748c717a6c3a36
Thanks,
Seth Rowe
Altman wrote:
OK I was having rounding problems before and I didn't realize that
their was a third parameter in the round function that would tell it if
it a 5 to round up. I thought adding this would fix the problem but it
didn't. I have VS 2005 and I am using vb.net try rounding the number
4.935 to 2 decimals:
What I am seeing is the following:
Math.Round(4.935, 2, MidpointRounding.AwayFromZero) 'Result is 4.93
Math.Round(4.935, 2, MidpointRounding.ToEven) 'Result is
4.93
Is this a bug? Am I just missing something?
I want 5 to round up which means AwayFromZero should do it right? In
this case even if I did ToEven it should go to 4.94 but it isn't. Is
it best to just abandon the round function in .Net and make my own. I
feel that rounding is such a basic function that I shouldn't have to
make my own function. Is this a floating point problem with .Net?
Right now I don't know if I can trust the round function that is built
in.
I notice that if I do the following:
Math.Round(ctype(4.935, Decimal), 2, MidpointRounding.AwayFromZero)
I get the desired result. Is there any problem converting a double to
a decimal like this?
rowe_newsgroups wrote:
Is this a bug?
As far as I'm concerned, yes. Check out this similar thread to see an
explaination:
http://groups.google.com/group/micro...748c717a6c3a36
Thanks,
Seth Rowe
Altman wrote:
OK I was having rounding problems before and I didn't realize that
their was a third parameter in the round function that would tell it if
it a 5 to round up. I thought adding this would fix the problem but it
didn't. I have VS 2005 and I am using vb.net try rounding the number
4.935 to 2 decimals:
What I am seeing is the following:
Math.Round(4.935, 2, MidpointRounding.AwayFromZero) 'Result is 4.93
Math.Round(4.935, 2, MidpointRounding.ToEven) 'Result is
4.93
Is this a bug? Am I just missing something?
I want 5 to round up which means AwayFromZero should do it right? In
this case even if I did ToEven it should go to 4.94 but it isn't. Is
it best to just abandon the round function in .Net and make my own. I
feel that rounding is such a basic function that I shouldn't have to
make my own function. Is this a floating point problem with .Net?
Right now I don't know if I can trust the round function that is built
in.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Radioactive Man |
last post by:
In python 2.3 (IDLE 1.0.3) running under windows 95, I get the
following types of errors whenever I do simple arithmetic:
1st example:
>>> 12.10 + 8.30
20.399999999999999
>>> 1.1 - 0.2...
|
by: Tom |
last post by:
Has anyone ever seen a IComparer for floats the returns magnitude.
i.e. instead of returning -1, it would return -5. To let you know HOW
different the two numbers are. obviously for int it is a -...
|
by: Ark |
last post by:
Hi everyone,
Does anyone know if Direct3D overloads System.Math
functions?
Also is it possible to access the base functions of the
overloaded function (in other words restore original of
the...
|
by: ng_mr |
last post by:
No, not a question about "banker's rounding" or whatever it's called.
I want to round a double to the nearest 100th, so I perform the
following:
// original is a double
double result =...
|
by: Gregory Pietsch |
last post by:
I'm writing a portable implementation of the C standard library for
http://www.clc-wiki.net and I was wondering if someone could check the
functions in math.h for sanity/portability/whatever. I'm...
|
by: David Coleman |
last post by:
I am running VS 2003 and have applied SP1. (On WinXP SP2, .Net 1.1)
In the Command Window I get the following
? Math.Round(0.715, 2)
0.72
? Math.Round(0.725, 2)
0.72
? Math.Round(0.735, 2)...
|
by: Zeng |
last post by:
Math.Round has good behavior as following:
Math.Round(3.45, 1); //Returns 3.4. The last '5' is thrown away because 4 is
even
Math.Round(3.75, 1); //Returns 3.8. The last '5' is used because '7'...
|
by: =?Utf-8?B?UmVuZQ==?= |
last post by:
Hello everyone
I have a problem with Math.Round, it´s ocurring some strange:
Math.Round(12.985) = 12.98, it´s wrong. It should be: 12.99
Why?? What is the problem?
Help ME !!!!
|
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= |
last post by:
Hi,
Why does Math.Sqrt() only accept a double as a parameter? I would think
it would be just as happy with a decimal (or int, or float, or ....). I can
easily convert back and forth, but I am...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |