0

I have used decimal.round() method in c# which return as decimal.round (112.5) returns 112 but when I use round method in SQL server as select round (112.5,0) it return 113. What is the fault? Can anyone help me ?

3 Answers3

3
Math.Round(112.5, MidpointRounding.AwayFromZero);
dlxeon
  • 1,932
  • 1
  • 11
  • 14
1

SQL Server's ROUND method rounds .5 up always while (in default mode) Math.Round rounds to even (so 1.5 becomes 2, but 4.5 becomes 4). Round to even is commonly know as "Banker's Rounding".

Depending on which behaviour you want you can:

Richard
  • 106,783
  • 21
  • 203
  • 265
1

You need to check the documentation for the decimal.round.

The integer that is nearest to the d parameter. If d is halfway between two integers, one of which is even and the other odd, the even number is returned.

https://msdn.microsoft.com/en-us/library/k4e2bye2(v=vs.110).aspx

The solution is to have a MidpointRounding parameter.

Please check this for simple samples: http://www.dotnetperls.com/math-round

Community
  • 1
  • 1
Fritz
  • 41
  • 6