Dav*_*emp 21
你可以施放:
int ItemCount = (int) Math.Ceiling( (decimal)BrandCount / 4m );
Run Code Online (Sandbox Code Playgroud)
此外,因为int/ decimal结果decimal你可以删除其中一个演员:
int ItemCount = (int) Math.Ceiling( BrandCount / 4m );
Run Code Online (Sandbox Code Playgroud)
Mot*_*tti 11
为什么你甚至使用小数?
int ItemCount = (BrandCount+3)/4;
Run Code Online (Sandbox Code Playgroud)
在+3确保你圆了,而不是下降:
(37+3)/4 == 40/4 == 10
(38+3)/4 == 41/4 == 10
(39+3)/4 == 42/4 == 10
(40+3)/4 == 43/4 == 10
Run Code Online (Sandbox Code Playgroud)
一般来说:
public uint DivUp(uint num, uint denom)
{
return (num + denom - 1) / denom;
}
Run Code Online (Sandbox Code Playgroud)
Mod的更长的选择.
ItemCount = BrandCount / 4;
if (BrandCount%4 > 0) ItemCount++;
Run Code Online (Sandbox Code Playgroud)