I have this extension method, but I don't know whether there is already a built in operator for it or if there is a name for it:
public static class IntegerExtensions
{
public static int DivideWholeAndPartial(this int total, int divisor)
{
return (total / divisor) +
((total % divisor) == 0 ? 0 : 1);
}
}
Essentially if the total divides equally, then that is returned. If there are any remainders it is rounded up - i.e. include partials as a whole. Kind of like a "How many One litre bottles are needed to hold 3.5 litres of water" problem.
Am I missing any built in C# methods? Is there a name for this?
I think Ceiling
does what you want:
return (int)Math.Ceiling((double)total / (double)divisor);
.. but I think you'll have to keep your extension method, as there isn't a built-in method that does this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With