What is the round() method?

October 30th, 2009 by uCertify Leave a reply »

The round() method is a static method of the java.lang.Math class. It takes a floating-point number as an argument and returns an integer representation of the number. The value returned by the round() method is the same as the value returned by the Math.floor() method in the following conditions:

  • if the argument to the round() method is a positive number and the fractional part of the number is less than 0.5.
  • if the argument to the round() method is a negative number and the fractional part of the number is greater than 0.5.

The value returned by the round() method is the same as the value returned by the Math.ceil() method in the following conditions:

  • if the argument to the round() method is a positive number and the fractional part of the number is greater than or equal to 0.5.
  • if the argument to the round() method is a negative number and the fractional part of the number is less than or equal to 0.5.

The round() method is overloaded with separate versions for float and double arguments. The signatures of the two versions of the round() method are given below:

public static int round(float num)
public static long round(double num)

The first version of the method takes a float type value as an argument and returns a number after rounding off the value to the nearest int value.

The second version of the method takes a double type value as an argument and returns a number after rounding off the value to the nearest long value.

  • Share/Bookmark
Advertisement

Leave a Reply

uCertify.com | Our Company | Articles | Contact Us | News and Press Release | uCertify India | Entries (RSS)
MCSE: MCSA, MCTS, MCITP    JAVA Certification: SCJP, SCWCD    Cisco Certification: CCNA, CCENT    A+, Network+, Security+ Project+
Oracle Certification: OCP 11g, OCP 10g, OCA 11g, OCA 10g    CIW foundation    EC-212-32,    CISSP    Photoshop ACE CS4    Adobe Flash ACE, PMP, CAPM
© 2008 uCertify.com. All rights reserved. All trademarks are the property of their respective owners.