This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes rounding a number (ceiling)? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "rounding a number (ceiling)?" Watch "rounding a number (ceiling)?" New topic
Author

rounding a number (ceiling)?

mark babcock
Greenhorn

Joined: Jun 26, 2002
Posts: 14
I'm trying to round an integer.
lets say I have:
x = 22;
y = (x/10);
y would return 2.2 I want it to round up to the next whole number no matter what the decimal value. I was looking for a ceiling function. But, can't seem to find anything that does this.
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2849
    
  11

Math.ceil(num)
This takes a double argument and returns a double, though the return value will be equal to an integer, so you can just cast it.
Remember integer division will trucate to an integer, e.g.,

will print out 0. You may want to make x a double, or cast it to double before dividing.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: rounding a number (ceiling)?