I have a menu of product brands that I want to split over 4 columns. So if I have 39 brands, then I want the maximum item count for each column to be 10 (with a single gap in the last column. Here's how I'm calculating the item count for a column (using C#):
int ItemCount = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(BrandCount) / 4m));
All that conversion seems really ugly to me. Is there a better way to do math on integers in C#?
You can cast:
int ItemCount = (int) Math.Ceiling( (decimal)BrandCount / 4m );
Also, because int
/decimal
results in a decimal
you can remove one of the casts:
int ItemCount = (int) Math.Ceiling( BrandCount / 4m );
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