File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Math.Ceil ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Math.Ceil ??" Watch "Math.Ceil ??" New topic

Math.Ceil ??

Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
Can any one tell me. Why am i getting 1.0 here in the following code instead of 2.0

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Horatio Westock
Ranch Hand

Joined: Feb 23, 2005
Posts: 221
OK. Try:

pgno = Math.ceil(15.0/8);

Then think: what the difference is between the two lines?
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
If you read the api the method Math.ceil has the following signature :
public static double ceil(double a)

However when you divide 15/8 you return an int, if you divide 15.0/8.0 you are using a floating point hence the the answer will be a double and the Math.ceil method will function as required.
[ March 17, 2005: Message edited by: Nigel Browne ]
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
Thanks Guys.I got it.
I agree. Here's the link:
subject: Math.Ceil ??
It's not a secret anymore!