This problem has driven me crazy. I am using Microsoft SQLExpress 2016 to write a stored procedure. One of the requirement is to do rounding. But every now and then, the rounding is wrong. I found out that T-SQL rounding is not exactly the same with C#, but why?
Compare two rounding below:
In T-SQL: ROUND(0.045, 2) --> this will produce 0.05 In C#: Math.Round(0.045, 2) --> this will produce 0.04
Why C# produces 0.04? Shouldn't it be 0.05?
What should I do so that C# rounding = T-SQL rounding? Can anyone help me?
Out of curiousity, I tried this in C#:
Guess, what C# rounded it to? It rounded to 0.06! Now, I am completely confused!
Math.Round(0.045, 2) //this becomes 0.04 Math.Round(0.055, 2) //this becomes 0.06
Can anyone explain this?