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?

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.


Edit this Article
Math Round Down Math.Round() Round Down to nearest number AspNet 6 ebook e-book Rounding Down to Nearest Integer .NET 6 published
Was this page helpful?
Yes Yes! this solution to the problem was helpful. No No! this solution to the problem was not helpful.. Leave ErnesTech Feedback.Feedback
If you log in, you will be notified when someone leaves a comment.

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

Your Session is Ending
Login to Continue

© 2021 - ErnesTech - Privacy