int n = 5;
int quorum = Math.Floor(n / 2) + 1;
I’m expecting quorum to have value 3. But this is the error I get in VisualStudio:
The call is ambiguous between the following methods or properties: ‘System.Math.Floor(double)’ and ‘System.Math.Floor(decimal)’
How do I correct it? Where did I go wrong?
You have no need to use
Math.Floor. Because all of your terms are integers, .NET will perform integer division which automatically truncates the remainder of the output anyway.As for why you’re getting the error, as stated above the result of integer division is still an integer. Because you can’t floor an integer (there’s no fractional component to round down), there’s no overload of
Floorthat takes anint. The call would have to convert the result to adecimalordoublefirst, and the compiler doesn’t know which one you want (which is, in fact, neither).