Math.Ceiling
returns double
because double
may store much bigger numbers. However if i'm sure that int
type is capable to store the result how should I convert? Is it safe to cast (int) Math.Ceiling(...
?
the result is an int , the value of which is a divided by b , rounded toward zero. Because the result is already rounded, ceil() doesn't do anything. Note that this rounding is not the same as floor() , which rounds towards negative infinity.
ceil() method with the help of examples. The ceil() method rounds the specified double value upward and returns it. The rounded value will be equal to the mathematical integer. That is, the value 3.24 will be rounded to 4.0 which is equal to integer 4.
The Math. Ceiling() method in C# is used to return the smallest integral value greater than or equal to the specified number.
If you are sure that you do not cross the capacity of int, it should be perfectly safe to do
int myInt = (int)Math.Ceiling(...);
If you are not sure about the bound, you could go with long
instead of int
.
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