i am trying to find total pages in building a pager on a website (so i want the result to be an integer. i get a list of records and i want to split into 10 per page (the page count)
when i do this:
list.Count() / 10
or
list.Count() / (decimal)10
and the list.Count() =12
, i get a result of 1
.
How would I code it so i get 2
in this case (the remainder should always add 1
)
Rounding to the Nearest Integer If the digit in the tenths place is less than 5, then round down, which means the units digit remains the same; if the digit in the tenths place is 5 or greater, then round up, which means you should increase the unit digit by one.
To implement the “rounding up” strategy in Python, we'll use the ceil() function from the math module. The ceil() function gets its name from the term “ceiling,” which is used in mathematics to describe the nearest integer that is greater than or equal to a given number.
The Math. Round() function can be used to round up a double value to the nearest integer value in C#. The Math. Round() function returns a double value that is rounded up to the nearest integer.
Math.Ceiling((double)list.Count() / 10);
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