• Post Reply Bookmark Topic Watch Topic
  • New Topic
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
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

round() returns ?

 
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
round (double) < -- returns long
I was under the impression that methods of Math return either int or double.
Where am I wrong?
TIA
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Paul
how come u have such umpression ? You should check the apis' again... :-)
Rajinder is perfectly right on your answer.
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Time is the best teacher, but unfortunately, it kills all of its students - Robin Williams. tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic