C# ToEven property


The ToEven property is used with the MidpointRounding Enumeration to round a number to the nearest even number.

Declare and initialize a decimal number −

decimal val = 70.45M;

To rounde a number to the nearest even number −

decimal.Round(val, 0, MidpointRounding.ToEven)

Here is the complete code −

Example

 Live Demo

using System;
using System.Linq;

class Demo {
   static void Main() {
      decimal val = 70.45M;
      Console.WriteLine(decimal.Round(val, 0, MidpointRounding.ToEven));
   }
}

Output

70

Updated on: 22-Jun-2020

43 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements