.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:
value1
is the only required parameter and is either a decimal or double.value2
would 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 theMidpointRounding
enum
.value3
would be the mode ifvalue2
was 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.