## Rounding Numbers

Put your problem here if it does not fit any of the other categories.

### Rounding Numbers

Hello there,

I have been playing around with rounding numbers for quite some time trying to figure this one out. I have tried a few things such as BigDecimal, Math.round, and NumberFormat. But have not gotten any of them correct. I am looking for a way that I could do something as follows:
Code: Select all
`1.0 = 11.1 = 21.5 = 22.0 = 22.2 = 3`

In words, I would like to round the number up if it is bigger than the previous whole number, rather than up at "x.5"

What would be the easiest method of completing this task?
ulatec
Junior Developer

Posts: 13
Joined: Sat Mar 27, 2010 2:09 am

### Re: Rounding Numbers

around 12 lines of code, wrapped in a static method??
anarche
Master Developer

Posts: 369
Joined: Sun Apr 11, 2010 5:21 am

### Re: Rounding Numbers

anarche wrote:around 12 lines of code, wrapped in a static method??

Huh?
If I do put this in a static method, what operations would I use?
ulatec
Junior Developer

Posts: 13
Joined: Sat Mar 27, 2010 2:09 am

### Re: Rounding Numbers

What anarche is suggesting is you could write your own method (a static one even!) to do this for you.

But...why do that when it is already done for you!!!

Math.ceil(double)
nicholas.hauschild
Master Developer

Posts: 310
Joined: Fri Dec 04, 2009 4:50 am

### Re: Rounding Numbers

Oh my gosh! Thank you so much, I somehow must have missed that. Thanks you very much Nicholas
ulatec
Junior Developer

Posts: 13
Joined: Sat Mar 27, 2010 2:09 am