C Sharp (C#) Double datatype


The Double datatype is used whenever fractional values need to be assigned to a variable. Its similar to an integer datatype but has a very big range of values which can accept fractional values. Double is the most popular datatype used in most of the mathematical functions in C# while using the Math library or just assigning values.

When a variable is assigned a value which is double, then it needs to be suffix with "D" or "d".

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            double a = 22D;
            double b = 7D;
            double pivalue = a / b;// float answer = (a * a) + (b * b) + (2 * a * b); //a squared + b squared + 2ab
            Console.WriteLine("The final value of {0} / {1} is : {2}", a, b, pivalue);
            Console.ReadLine();

            double number = 1.2345D;
            double power = 2.5D;
            double finalanswer = Math.Pow(number, power);
            Console.WriteLine("The {0} to the power of {1} is {2}", number, power, finalanswer);
            Console.ReadLine();
        }
    }
}

Output:

C Sharp Datatypes Home Page

No comments: