![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Round a number to the nearest even number in C#
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 = 25.55M;
To round a number to the nearest even number −
decimal.Round(val, 0, MidpointRounding.ToEven)
Here is the complete code −
Example
using System; using System.Linq; class Demo { static void Main() { decimal val = 25.55M; Console.WriteLine(decimal.Round(val, 0, MidpointRounding.ToEven)); } }
Output
26
Advertisements