Java MathcopySign() 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
ThecopySign() method returns the value of the first number with the sign of the second number.
Syntax
One of the following:
public static double copySign(doublevalue, doublesign)public static float copySign(floatvalue, floatsign)Parameter Values
| Parameter | Description |
|---|---|
| value | Required. A number which determines the value. |
| sign | Required. A number which determines the sign. |
Technical Details
| Returns: | Adouble orfloat with the value of the first number and the sign of the second number. |
|---|---|
| Java version: | 1.6+ |
❮ Math Methods

