jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes round() returns ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "round() returns ?" Watch "round() returns ?" New topic

round() returns ?

Paul Salerno
Ranch Hand

Joined: Jan 17, 2002
Posts: 172
round (double) < -- returns long
I was under the impression that methods of Math return either int or double.
Where am I wrong?
Matt Ghiold
Ranch Hand

Joined: Feb 24, 2002
Posts: 213
If you look at the api, it states that the round method of the math class returns a long for a double and an int for a float hope this helps.

-Matt<br /> SCJP2<br /> SCJD
Rajinder Yadav
Ranch Hand

Joined: Jan 18, 2002
Posts: 178
The point of the round() function is to convert a floating point value and return the closest integer value, so it doesn't makes sense to return a type double?

<a href="http://www.rajindery.com" target="_blank" rel="nofollow">Rajinder Yadav</a><p>Each problem that I solved became a rule which served afterwards to solve other problems. --Rene Descartes
Nazmul Huda Sarkar
Ranch Hand

Joined: Feb 01, 2002
Posts: 317
Hello Paul
how come u have such umpression ? You should check the apis' again... :-)
Rajinder is perfectly right on your answer.

Nazmul<br />SCJP,SCWCD,IBM OOAD with UML
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
I am not defending Paul because he sounds like a latin person , but he is right if he says that most of the methods in the Math class returns a double, apart from overloaded versions. round is the only method that doesn't do that.
Also most of the methods in the class Math take a double, apart from overloded ones. There is again one exception random that doesn't takes anything.
These knowledge was useful to me when taking the exam and it's easy to remember.
[ March 04, 2002: Message edited by: Jose Botella ]

SCJP2. Please Indent your code using UBB Code
I agree. Here's the link: http://aspose.com/file-tools
subject: round() returns ?
It's not a secret anymore!