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.
- Download free practice test for master-ciw-enterprise-developer Master CIW Enterprise Developer exam.
- Click here to download scbcd test study guide and practice question.
- Pass SCDJWS in first attampt.
- Click here to get free scjp SCJP exam practice questions.
- Pass SUN scjp-5-0 - SCJP 5/6
- Best exam simulation SUN scmad download free trial.
- Pass SCWCD in first attampt.
- Click here to download 310-035 test study guide and practice question.
- Best exam simulation SUN CX310-055 download free trial.
- Pass SUN CX310-056 - SCJP 5.0 Java Upgrade
- Download practice question and study guide for CX310-066 for exam.
If you like this article, please leave a comment or subscribe this blog via RSS or via e-mail, Bookmark and share through your network. Click the AddThis button below. Thanks.
