+ 1

Why doesn't this work?

double idk; idk = 3/2; Console.WriteLine(idk); Console.ReadLine(); The output is 1 ,

28th Sep 2018, 1:33 PM
Firephoenix 95
Firephoenix 95 - avatar
2 Respostas
+ 1
Don't know much C#, but it seems since the two literals are integers (as none of them were written with decimal points) I guess the result of integer division is then assigned to <idk>. You might want to try divide with floating point literals (3.0/2) or use type indicator (3f/2) idk = 3.0/2; idk = 3f/2; (Edit) You can also have a double variable to be the left operand here; double a = 3; double b = a / 2; Console.WriteLine(b);
28th Sep 2018, 1:51 PM
Ipang
+ 1
What Ipang says it true. quotte from the link: When you divide two integers, the result is always an integer. https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/division-operator Have a look in my code https://code.sololearn.com/ceCVzUfPamlN
29th Sep 2018, 7:30 PM
sneeze
sneeze - avatar