How to print floating point value in C#

2 Answers

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            double d = 3.14159265359;

            Console.WriteLine(d);
            Console.WriteLine("{0:F2}", d);
        }
    }
}


/*
run:

3.14159265359
3.14

*/

 



answered Mar 1, 2017 by avibootz
0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            double d = 10.35 * 3.14;

            Console.WriteLine(d);
            Console.WriteLine("{0:F20}", d);
            Console.WriteLine(string.Format("{0:F20}", d));
            Console.WriteLine(d.ToString());
        }
    }
}


/*
run:

32.499
32.49900000000000000000
32.49900000000000000000
32.499

*/

 



answered Mar 2, 2017 by avibootz
...