Java Number class
Generally, when we need to use numbers, we usually use built-in data types, such as: byte, int, long, double, etc.
Example
int i = 5000; float gpa = 13.65; byte mask = 0xaf;
However, in the actual development process, we often encounter situations where we need to use objects instead of built-in data types. In order to solve this problem, the Java language provides corresponding wrapper classes for each built-in data type.
All wrapper classes (Integer, Long, Byte, Double, Float, Short) are subclasses of the abstract class Number.
This kind of packaging specially supported by the compiler is called boxing, so when a built-in data type is used as an object, the compiler will box the built-in type into a packaging class . Similarly, the compiler can unbox an object into a built-in type. Number class belongs to java.lang package.
The following is an example of boxing and unboxing:
public class Test{ public static void main(String args[]){ Integer x = 5; // boxes int to an Integer object x = x + 10; // unboxes the Integer to a int System.out.println(x); } }
The compilation and running results of the above example are as follows:
15
When x is assigned to an integer value, because x is an object, so the compiler needs to box x. Then, in order for x to be added, x is unboxed.
Member methods of Number class The following table lists the methods of Number class: Serial number Methods and descriptions 1 xxxValue() 2 compareTo() 3 equals() 4 valueOf() 5 toString() 6 parseInt() 7 abs() 8 ceil() 9 floor() 10 rint() 11 round() 12 min() 13 max() 14 exp() 15 log() 16 pow() 17 sqrt() 18 sin() 19 cos() 20 tan() 21 asin() 22 acos() 23 atan() 24 atan2() 25 toDegrees() 26 toRadians() 27 random() The above is the content of [java tutorial] Java Number class. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!
Convert the number object to a value of xxx data type and return it.
Compare the number object with the parameter.
Determine whether the number object is equal to the parameter.
returns the built-in data type specified by an Integer object
returns the value in string form.
Parse the string into int type.
returns the absolute value of the parameter.
rounds the integer variable to the left, and the return type is double.
rounds the integer variable to the right. The return type is double.
Returns the integer closest to the parameter. The return type is double.
returns the nearest int or long value.
returns the minimum value of the two parameters.
returns the maximum value of the two parameters.
returns the parameter power of the natural number base e.
returns the logarithm of the natural number base of the parameter.
returns the first parameter raised to the power of the second parameter.
Find the arithmetic square root of the parameter.
Find the sine value of the specified double type parameter.
Find the cosine value of the specified double type parameter.
Finds the tangent value of the specified double type parameter.
finds the arcsine value of the specified double type parameter.
Finds the inverse cosine value of the specified double type parameter.
finds the arctangent value of the specified double type parameter.
Convert Cartesian coordinates to polar coordinates and return the angle value of the polar coordinates.
Convert parameters into angles.
Convert angles to radians.
returns a random number.