I'm starting to learn C #. I decided to write a simple console converter. Explain, please, why the following line of code does not work:
double nCels = Convert.ToDouble ( (nFahr - 32)*(5/9)); Console.WriteLine(nCels); Any nFahr returns 0
Try this:
Console.WriteLine( (double)((nFahr - 32)*(5/9)) ); It is called "Explicit conversion", you can read about conversions and type conversions on MSDN
*(5/9) for some reason, it persistently returns 0. But /1.8 gives the correct result. - sergarcadaint operator / performs division without remainder, to get a double , as already mentioned, you need to add zero or the letter d - 5d/9d - SpecterSource: https://ru.stackoverflow.com/questions/115348/
All Articles