Q:

C# program to demonstrate the use of Round() method of Math class

belongs to collection: C# Math Class Programs

0

C# program to demonstrate the use of Round() method of Math class

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to demonstrate the use of Round() method of Math class is given below. The given program is compiled and executed successfully.

using System;
class Sample
{
    //Entry point of Program
    static public void Main()
    {
        double val = 0.0;
        decimal decVal = 0.0M;

        Console.WriteLine("Demonstration of Round Method: ");
        val = Math.Round(2.4);
        Console.WriteLine("Value : "+val);

        val = Math.Round(2.5);
        Console.WriteLine("Value : " + val);

        val = Math.Round(2.6);
        Console.WriteLine("Value : " + val);

        val = Math.Round(2.4567,2);
        Console.WriteLine("Value : " + val);

        val = Math.Round(2.4567, 3);
        Console.WriteLine("Value : " + val);

        decVal = Math.Round(2.4567M, 2);
        Console.WriteLine("Decimal Value : " + decVal);

        decVal = Math.Round(2.4567M,MidpointRounding.AwayFromZero);
        Console.WriteLine("Decimal Value : " + decVal);
    }
}

Output:

Demonstration of Round Method:
Value : 2
Value : 2
Value : 3
Value : 2.46
Value : 2.457
Decimal Value : 2.46
Decimal Value : 2
Press any key to continue . . .

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# program to demonstrate the use of DivRem() meth... >>
<< C# program to demonstrate the use of Abs() method ...