math.round

Getting different result in Math.Round

ticketPriceInPence = 7360 percentageToRefund = 100 (int)(Math.Round((ticketPriceInPence * 0.01) * (percentageToRefund * 0.01), 2, MidpointRounding.AwayFromZero) * 100) This results in : 73.59 (int)(Math.Round((ticketPriceInPence * 0.01) * (percentageToRefund * 0.01) * 100, 2, MidpointRounding.AwayFromZero)) This results in : 73.60 ...

Is there a way to do 'correct' arithmetical rounding in .NET? / C#

I'm trying to round a number to it's first decimal place and, considering the different MidpointRounding options, that seems to work well. A problem arises though when that number has sunsequent decimal places that would arithmetically affect the rounding. An example: With 0.1, 0.11..0.19 and 0.141..0.44 it works: Math.Round(0.1, 1) ...

Math.Round methodology, starting at the smallest decimal

There have been many threads started over the confusion in the way that Math.Round works. For the most part, those are answered by cluing people in to the MidpointRounding parameter and that most people are expecting MidpointRounding.AwayFromZero. I have a further question though about the actual algorithm implemented by AwayFromZero. G...

Math.Round for decimal

Hi All, I am running this code: decimal d = 1.45M; Console.WriteLine((System.Math.Round(d,0,MidpointRounding.AwayFromZero).ToString())); Here I expect the output to be 2 because 1.45 when rounded to 1st decimal place will be 1.5 which when next rounded to 0 decimal places should be 2. However, I am getting the answer as 1. Is my ...

C# banker's rounding error

double a = 18.565 return Math.Round(a,2) ..returns 18.57. For every other number I tried banker's rounding worked as expected, for example Math.Round(2.565,2) returned 2.56. Any clue why and when that happens? Is it error or am I missing something about banker's rounding? Thanks.. ...