CSharp - Write program to Working with Floating Point Numbers


Distinguish between whole and decimal numbers.

Use type called double for decimal numbers.


using System;

class Program/*from   w w  w. j a  v a2s. c  om*/
    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);




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.