C# .Round()
Published Apr 18, 2023
Contribute to Docs
The Math.Round() class method returns a value rounded to the nearest integer.
Syntax
Math.Round(value1, value2, value3);
The Math.Round() method takes up to three parameters:
value1is the only required parameter and is either a decimal or double.value2would be an integer ranging from -2,147,483,648 to 2,147,483,647 (int32), or it could be a specific mode that is called from theMidpointRoundingenum.value3would be the mode ifvalue2was of type int32. The modes include:ToEven,AwayFromZero,ToZero, andTowardZero.
Example
The following example passes one argument as a parameter:
using System;public class Example {public static void Main(string[] args) {decimal val1 = 10.2m;val1 = Math.Round(val1);Console.WriteLine("Rounded value is " + val1);}}
The example will result in the following output:
Rounded value is 10
Codebyte Example
The following example passes three arguments into the method:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn C# on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn Microsoft's popular C# programming language, used to make websites, mobile apps, video games, VR, and more.
- Beginner Friendly.15 hours