
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
MathF.Round() Method in C# with Examples
The MathF.Round() method in C# is used to round a value to the nearest integer or to the particular number of fractional digits.
Syntax
Following is the syntax −
public static float Round (float x); public static float Round (float x, int digits); public static float Round (float x, int digits, MidpointRounding mode); public static float Round (float x, MidpointRounding mode);
Example
Let us now see an example to implement the MathF.Round() method −
using System; public class Demo { public static void Main(){ float val1 = 15.20f; float val2 = 3.10f; Console.WriteLine("Rounded (val1) = "+MathF.Round(val1)); Console.WriteLine("Rounded (val2) = "+MathF.Round(val2)); } }
Output
This will produce the following output −
Rounded (val1) = 15 Rounded (val2) = 3
Example
Let us now see another example to implement the MathF.Round() method −
using System; public class Demo { public static void Main(){ float val1 = 10.23898f; float val2 = 20.878788f; Console.WriteLine("Rounded (val1) = "+MathF.Round(val1,2)); Console.WriteLine("Rounded (val2) = "+MathF.Round(val2,3)); } }
Output
This will produce the following output −
Rounded (val1) = 10.24 Rounded (val2) = 20.879
- Related Articles
- MathF.Tan() Method in C# with Examples
- MathF.Tanh() Method in C# with Examples
- MathF.Truncate() Method in C# with Examples
- MathF.Sin() Method in C# with Examples
- MathF.Sinh() Method in C# with Examples
- MathF.Sqrt() Method in C# with Examples
- Boolean.GetHashCode() Method in C# with Examples
- Single.Equals() Method in C# with Examples
- Single.CompareTo() Method in C# with Examples
- SByte.ToString() Method in C# with Examples
- Boolean.GetTypeCode() Method in C# with Examples
- Double.CompareTo Method in C# with Examples
- Double.Equals() Method in C# with Examples
- Single.IsPositiveInfinity() Method in C# with Examples
- Single.GetTypeCode Method in C# with Examples

Advertisements