I’m having a weird problem and I’m pretty sure I’m missing something.
decimal pages = Math.Ceiling((decimal)(927/1027));
MessageBox.Show(pages.ToString());
927/1027 = 0.902….. so this should return 1 right?
Instead I get 0.
But when I directly input the value to Ceiling,
decimal pages = Math.Ceiling((decimal)(0.902));
MessageBox.Show(pages.ToString());
I get 1 as expected. Am I missing something?
927/1027is an integer expression that evaluates to theintwith value0.If you want a decimal calculation then you should do it like this:
The
msuffix indicates a literal of typedecimal.But that itself would be somewhat odd since
Math.Ceilingreceives a floating point parameter as input. So, if you are usingMath.Ceilingthen I think that you really want to use floating point division. Like this: