PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, July 18, 2022

[FIXED] Why double becomes int?

 July 18, 2022     c#, double, integer     No comments   

Issue

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"?


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))


Answered By - redParrot
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing