JohnChris JohnChris - 4 months ago 31
C# Question

Math.Sqrt(2/3) returns 0

I am really confused why this is happening, my code:

double x = Math.Sqrt(2/3);

Displays 0.
The answer is

0.8164, I know I will also have to use Math.Round to round this up, but for the moment the issue is I'm getting 0


The problem is caused by automatic integer evaluation of the numbers. Use:

double x = Math.Sqrt(2f/3f);