473,382 Members | 1,563 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Decimal Round Up Question

I found the decimal round up problem,

System.Math.Round(106.865, 2)= 106.86
System.Math.Round(106.875, 2) = 106.88
System.Math.Round(106.885, 2) = 106.88
System.Math.Round(106.895, 2) = 106.9

Why some time it round up the 5 and sometime roun down the 5 ?
Oct 4 '06 #1
2 8440
Tsair,

Because DotNet uses the ISO Banking rounding method. On my question in these
newsgroups who was using that beside Banks (between each other not to
customers) I never got any anser.

In past there where a lot of articles about that on MSDN but I cannot find
them anymore. It is about the even and odd situation of a value that tells
it it is rounded up or down.

Cor
"Tsair" <ts***@myjaring.netschreef in bericht
news:eb**************@TK2MSFTNGP02.phx.gbl...
>I found the decimal round up problem,

System.Math.Round(106.865, 2)= 106.86
System.Math.Round(106.875, 2) = 106.88
System.Math.Round(106.885, 2) = 106.88
System.Math.Round(106.895, 2) = 106.9

Why some time it round up the 5 and sometime roun down the 5 ?


Oct 4 '06 #2
Tsair <ts***@myjaring.netwrote:
I found the decimal round up problem,

System.Math.Round(106.865, 2)= 106.86
System.Math.Round(106.875, 2) = 106.88
System.Math.Round(106.885, 2) = 106.88
System.Math.Round(106.895, 2) = 106.9

Why some time it round up the 5 and sometime roun down the 5 ?
Firstly, just to be clear, this is talking about rounding the Double
type, not the Decimal type.

Secondly, this behaviour is as described in the documentation for
Math.Round:

<quote>
Return Value
The number nearest value with a precision equal to digits. If value is
halfway between two numbers, one of which is even and the other odd,
then the even number is returned. If the precision of value is less
than digits, then value is returned unchanged.
</quote>

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Oct 4 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
17
by: Rob Oldfield | last post by:
From the documentation about Decimal.Round.... "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...
687
by: cody | last post by:
no this is no trollposting and please don't get it wrong but iam very curious why people still use C instead of other languages especially C++. i heard people say C++ is slower than C but i can't...
4
by: Ron | last post by:
Greetings, int i = 1, j = 6; double k = (double)i/j; Console.WriteLine(k.ToString()); Console.WriteLine(string.Format(k.ToString(), "0.00")); both yield 0.166666666666667 how can I make...
4
by: vooose | last post by:
Consider a rounding up function: public static decimal RoundUp(decimal val, decimal round) { return ((decimal)Math.Ceiling((double)(val/round)))*round; } Math.Ceiling (and Math.Floor for...
4
by: spebola | last post by:
I am using vb.net 2003 professional and I get the following results when using the round method: dim Amount as decimal = 180.255 Amount = Amount.Round(Amount, 2) Amount now contains 180.25. ...
14
by: ray | last post by:
Dear all, In my vb.net program, I have to round a decimal number to two decimal place. For example, for the expression "Decimal.Round(31* 1.555, 2)", I should get the result "48.21". However, the...
13
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.