Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why double becomes int?

When I run this code, I get output "System.Double, 3"

namespace NewApp 
{
    class Program
    {
        static void Main(string[] args)
        {
            double a = 1.0;
            double b = 2.7;
            a = Math.Round(b);
            Console.WriteLine(a.GetType() + ", " + a);
        }

    }
}

Why I see "3", if a is double variable and I supposed to see "3.0"?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It is still double. You are facing with 3 instead of 3.0 because of the way Console.write works. Use this as example

Console.WriteLine(DoubleConverter.ToExactString(a))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading