Why is it a double and not an integer? | Sololearn: Learn to code for FREE!

Why is it a double and not an integer?

I know this may sound very stupid, (it's my first day) But is y a double instead of an integer, is it just because it is literally double than 10, the previous value? (Im not sure if i make sense) Here is the code copy-pasted from the lesson here. static void Main(string[] args) { int x = 10; double y = 20; // is it right or wrong to be a int instead of a double? Im very curious // Console.WriteLine("x = {0}; y = {1}", x, y); } // Output: x = 10; y = 20

9th Jan 2019, 1:11 AM
Ch P 🏹
Ch P 🏹 - avatar
1 Answer
+ 1
It has nothing to do with the fact that y is the double of x. Doubles are 15 digits long decimals, they're the double of a floating point (float) which are 7 digits long decimal numbers. However, you may still store integers in a floating point variable. Answering your question. It is a double just to a different datatype.
9th Jan 2019, 1:52 AM