CSharp - Write program to Rounding values

Requirements

The code will display decimal values with percent precision, round them to cents.

Then compare the calculation with the original values to the one with rounded values.

Hint

Define two fixed value as

double amount1 = 1234.56789;
double amount2 = 99.87654321;
        

Use them as the value to do the rounding

Demo

using System;
class Program{/* w  w  w  . j  a  v a 2  s.c  o m*/
    static void Main(string[] args){
        double amount1 = 1234.56789;
        double amount2 = 99.87654321;
        // Displaying inputs (original values) 
        Console.WriteLine("First amount (original value): " + amount1);
        Console.WriteLine("Second amount (original value): " + amount2);

        // Rounding just for output 
        Console.WriteLine("First amount displayed with cent precision: " + amount1.ToString("N2"));
        Console.WriteLine("Second amount displayed with cent precision: " + amount2.ToString("N2"));
        Console.WriteLine();

        // Rounding for further calculations + informative output 
        double roundedAmount1 = Math.Round(amount1, 2); // 2 = two decimal places
        double roundedAmount2 = Math.Round(amount2, 2);

        Console.WriteLine("First amount rounded to cents: " + roundedAmount1);
        Console.WriteLine("Second amount rounded to cents: " + roundedAmount2);
        Console.WriteLine();

        // Calculations 
        double sumOfOriginalAmounts = amount1 + amount2;
        double sumOfRoundedAmounts = roundedAmount1 + roundedAmount2;

        // Calculation outputs 
        Console.WriteLine("Sum of original amounts: " + sumOfOriginalAmounts.
        ToString("N2"));
        Console.WriteLine("Sum of rounded amounts: " + sumOfRoundedAmounts.
        ToString("N2"));
        Console.WriteLine("On invoice, we need sum of rounded amounts");

    }
}

Result