programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Ron McLeod
• Liutauras Vilda
• Paul Clapham
• paul wheaton
Sheriffs:
• Tim Cooke
• Devaka Cooray
• Rob Spoor
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Tim Moores
• Carey Brown
• Mikalai Zaikin
Bartenders:

# Math Class

Ranch Hand
Posts: 18944
• Number of slices to send:
Optional 'thank-you' note:
To all SCJP aspirants,
Make a note of the RETURN values of floor(),ceil(),and round() methods.
floor() - returns a double value
ceil() - returns a double value
round() - returns int,long value.
So the following code returns

float f = -3.2f;
System.out.println(Math.floor(f));
System.out.println(Math.ceil(f));
System.out.println(Math.round(f));
the values
-3.0
-3.0
-3 // an int.

Chandra

Anonymous
Ranch Hand
Posts: 18944
• Number of slices to send:
Optional 'thank-you' note:

Originally posted by Chandra:
To all SCJP aspirants,
Make a note of the RETURN values of floor(),ceil(),and round() methods.
floor() - returns a double value
ceil() - returns a double value
round() - returns int,long value.
So the following code returns

float f = -3.2f;
System.out.println(Math.floor(f));
System.out.println(Math.ceil(f));
System.out.println(Math.round(f));
the values
-3.0
-3.0
-3 // an int.

Chandra

Hi Chandra,
I found the following results to be:-
-4.0
-3.0
-3
Consider the following:-
ceil(-9.01) gives -9.0
ceil(9.01) gives 10.0
ceil(-0.1) gives -0.0
ceil(0.1) gives 1.0
ceil(-100) gives -100.0
ceil(100) gives 100.0
round(-5.49) gives -5 //goes more positive
round(5.49) gives 5

Anonymous
Ranch Hand
Posts: 18944
• Number of slices to send:
Optional 'thank-you' note:
Sorry for that. I wanted to convey that round() return -3 and not -3.0 (This is a tricky question in the Exam)
Thanks for the Correction,Rich
Chandra

 It's a tiny ad. At least, that's what she said. a bit of art, as a gift, that will fit in a stocking https://gardener-gift.com