CSharp - Write program to Working with Floating Point Numbers

Requirements

Distinguish between whole and decimal numbers.

Use type called double for decimal numbers.

Demo

using System;

class Program//  ww  w. jav  a2s  .c  o  m
{
    static void Main(string[] args)
    {
        double piApproximately = 3.14;

        // Pi is already available in C# 
        double piMorePrecisely = Math.PI;

        // Decimal numbers have always limited precision 
        double notCompletelyOne = 0.999999999999999999;

        // Outputs 
        Console.WriteLine("Pi value from our code: " + piApproximately);
        Console.WriteLine("Pi value from C#: " + piMorePrecisely);
        Console.WriteLine("This should not be exact one: " + notCompletelyOne);

    }
}

Result

Note

You always need to use a decimal point as a separator between the integer and decimal parts of a number.

decimal numbers do not have infinite precision. They are rounded after approximately 15 significant digits.