Java Math signum() Method
Example
Return the sign of different numbers:
System.out.println(Math.signum(12));
System.out.println(Math.signum(0.5));
System.out.println(Math.signum(0));
System.out.println(Math.signum(-0.25));
System.out.println(Math.signum(-6));
Definition and Usage
The signum()
method returns the sign of a number. A number's sign tells whether it is positive or negative. This method returns 1 for positive numbers, -1 for negative numbers and 0 for the number 0.
Syntax
public static double signum(double number)
public static float signum(float number)
Parameter Values
Parameter | Description |
---|---|
number | Required. A number to find the sign of. |
Technical Details
Returns: | A double or float value representing the sign of a number.Returns 1 for positive numbers, -1 for negative numbers and 0 for the number 0. |
---|---|
Java version: | 1.5+ |
❮ Math Methods