aspose file tools*
The moose likes Beginning Java and the fly likes Rouding up a number Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Rouding up a number" Watch "Rouding up a number" New topic
Author

Rouding up a number

Dave Mere
Ranch Hand

Joined: Oct 25, 2004
Posts: 37
Hi there,

As part of my pagination efforts, I need to round up a number to work out how many pages I need. So, where results is my ArrayList:



This outputs;
18
1.0
1.0

So 18 records returned (ok). The divide by 10 . . . = 1.0? What's going on?

How can I round up 18/10? Or generally work out how many pages I need for my 18 record resultset?

thanks!

Dave
Sam Bluesman
Ranch Hand

Joined: Nov 21, 2004
Posts: 191
http://www.coderanch.com/t/402346/java/java/Rounding-up

I had that problem


Moosey knows best
Dave Mere
Ranch Hand

Joined: Oct 25, 2004
Posts: 37
Sorted! Cheers Sam.

And on that note, I'm off to the pub . . .
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
For some reason I did a bunch of these in the waning days of my COBOL life, and just added divisor-1 before dividing. This linecount and pagecount case came up for a character mode help system. For ints:

pagecount = ( linecount + linesperpage - 1 ) / linesperpage


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
jQuery in Action, 2nd edition
 
subject: Rouding up a number