C# Tutorial C# Advanced C# Resources
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

C# - Math Sign() Method



The C# Math Sign() method returns an integer that indicates the sign of the argument. It returns zero if the argument is zero, 1 if the argument is greater than zero, -1 if the argument is less than zero. The method can be overloaded and it can take float, sbyte, int, long, double, decimal and short arguments.

Syntax

public static int Sign (float value);
public static int Sign (sbyte value);
public static int Sign (int value);
public static int Sign (long value);
public static int Sign (double value);
public static int Sign (decimal value);
public static int Sign (short value);

Parameters

value Specify a signed value.

Return Value

Returns an integer that indicates the sign of the argument.

Exception

throws ArithmeticException, if the argument is NaN.

Example:

In the example below, Sign() method returns an integer that indicates the sign of the argument.

using System;

class MyProgram {
  static void Main(string[] args) {
	Console.WriteLine(Math.Sign(48.45));   
	Console.WriteLine(Math.Sign(-48.667));  
	Console.WriteLine(Math.Sign(0));  
  }
}

The output of the above code will be:

1
-1
0

❮ C# Math Methods

5