C# Exercise Program - Rounding numbers
Question: Write a C# program to round a number to three decimal places
The following program takes a double as parameter and rounds the number to three decimal places. In this program we have tried to round Math.PI and a custom input number.Solution:
using System;
namespace CosmicLearn
{
public static class CosmicExercise
{
public static double Round3(double number)
{
return Math.Round(number, 3);
}
public static void Main(String[] args)
{
Console.WriteLine("Rounding Math.PI = " + Round3(Math.PI));
double number = 1.45674;
Console.WriteLine("Rounding number = " + Round3(number));
}
}
}
$count++; if ($count == 2) { include "../sharemediasubfolder.php"; } ?>