Short version: Why don't I have to coerce 60, and int, into a double, so that I can use division with another double if I DO care about the fractional part?
Long version: my boss called me out on a line of code. I tested it and it is working perfectly fine, but he thinks I have a bug waiting to happen.
int durationinseconds = 61; // This is actually filled from a double.tryparse
// from a string value out of an xml doc.
int durationinminutes = (int)Math.Ceiling((double)durationinseconds / 60);
My code is supposed to get the # of seconds from the XML doc, then figure out the # of minutes, always rounding up. 60 seconds = 1 minute, 61 seconds = 2 minutes, etc.
I've tested my code, but he INSISTS that the "/ 60" part should be "/ 60.0".
I've tested my code with 0, 1, 2, 59, 60, 61, 119, 120, 121, 599, 600, 601, etc, and it always works out correctly.
Before I go defend myself to him, I mostly understand why he thinks that I need to coerce 60 to be a decimal, because he thinks that if I use an int value then a double / int will result in an integer value, effectively dropping the fractional part.
However, that is not happening here, and I can't exactly explain why. So, that is my question: WHY don't I have to use 60.0 when dividing a double if I want to use the fractional part?