Java Math copySign() Method
Example
Return the value of a number with the sign of another:
System.out.println(Math.copySign(-4.7, 3));
System.out.println(Math.copySign(4.7, -2.5));
System.out.println(Math.copySign(3, 4));
System.out.println(Math.copySign(-2.5, -4.7));
Definition and Usage
The copySign()
method returns the value of the first number with the sign of the second number.
Syntax
One of the following:
public static double copySign(double value, double sign)
public static float copySign(float value, float sign)
Parameter Values
Parameter | Description |
---|---|
value | Required. A number which determines the value. |
sign | Required. A number which determines the sign. |
Technical Details
Returns: | A double or float with the value of the first number and the sign of the second number. |
---|---|
Java version: | 1.6+ |
❮ Math Methods