Rounding Down to the Nearest Decimal Point in C-Sharp (AspNet 6)

Question: How do you Round Down the number to the nearest decimal point in C#? the number I want to round down is 0.7777777777777777771, when I round use
Math.Round(MyNumber,02) the answer is 0.78. I don't want this answer, I wanted 0.77.

How do you do that with Math.Round() Method?


Please Login to see the rest of the answer

Answer: See the code below:

decimal myRoundDownValue = Math.Round(MyNumber,2,MidpointRounding.ToNegativeInfinity);
//Answer myRoundDownValue will be the actual value rounded to two decimal places.

Using the Math.Round(MyNumber,2,MidpointRounding.ToNegativeInfinity); will round down the value to two decimal places.  According to Visual Studio Intellisense, the MidpointRounding.ToNegativeInfinity enum rounds down with the result closest to and no greater than the infinitely precise result.


Write an Article
If you log in, you will be notified when someone leaves a comment.

Other users would like to know if this solution helped you.

Hy said:

If you want to get a positive number from a subtraction in C sharp just use Decimals and absolute values.


© 2022 - ErnesTech - Privacy