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:
• Tim Cooke
• Campbell Ritchie
• Ron McLeod
• Junilu Lacar
• Liutauras Vilda
Sheriffs:
• Paul Clapham
• Jeanne Boyarsky
• Henry Wong
Saloon Keepers:
• Tim Moores
• Tim Holloway
• Stephan van Hulst
• Piet Souris
• Carey Brown
Bartenders:
• Jesse Duncan
• Frits Walraven
• Mikalai Zaikin

# Math Class - Very Urgent

Ranch Hand
Posts: 82
• Number of slices to send:
Optional 'thank-you' note:
what is the nearest integer to -11.2.
And what method of Math class we should use to get the nearest integer value of -11.2.
Mahesh Bansal

Ranch Hand
Posts: 287
• Number of slices to send:
Optional 'thank-you' note:
I think it's the Math.round(float f) method.
float f=Math.round(-11.2)
This will give f the value of -11 as an integer value.
And Since -11 is the nearest integer to -11.2, you can say it's the "public int Math.round(float f)" method.
I hope I am correct, am I??
Bye,
Tualha Khan

Tualha Khan
Ranch Hand
Posts: 287
• Number of slices to send:
Optional 'thank-you' note:
Sorry, in the above code statement, it should be:
int f=Math.round(float f)

AND NOT
float f=Math.round(float f)
Got my mistake!!
Bye,
Tualha Khan

Ranch Hand
Posts: 318
• Number of slices to send:
Optional 'thank-you' note:
Math class has two round methods!
static�long round(double�a) ����������
Returns the closest long to the argument.
and
static�int round(float�a) ����������
Returns the closest int to the argument.
and in java if you do not specify anything
-11.2 will be a double and not a float
so the first one will be used

------------------
KS

Tualha Khan
Ranch Hand
Posts: 287
• Number of slices to send:
Optional 'thank-you' note:
God!
Again a silly mistake!!
Bye,
Tualha Khan

drifter
Posts: 1364
• Number of slices to send:
Optional 'thank-you' note:
Other important concepts needed for the exam are:
1) when to use Math.round() vs. Math.floor() or Math.ceil()
2) Math.floor() and Math.ceil() return double values.

Mahesh Bansal
Ranch Hand
Posts: 82
• Number of slices to send:
Optional 'thank-you' note:
Thanks a ton for the advise.
Mahesh

 pie. tiny ad: Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton