C# .Sign()
Published Nov 16, 2025
Contribute to Docs
The Math.Sign() method is a static method that returns an integer value indicating the sign of a specified number.
Syntax
Math.Sign(number);
Parameters:
number: The numeric value for which to determine the sign. Supported types include:sbyte,short,int,long,float,double, anddecimal.
Return value:
Returns an integer value that indicates the sign of the specified number:
-1: if the number is negative0: if the number is equal to zero1: if the number is positive
Example: Basic Usage of Math.Sign()
In this example, the sign of various numeric values is determined using the Math.Sign() method and printed to the console:
using System;public class Example {public static void Main () {// Example numeric valuesint numInt = -50;float numFloat = 0.0f;double numDouble = 2.7;decimal numDecimal = -0.01m;// Determine the sign of each numberint numIntSign = Math.Sign(numInt);int numFloatSign = Math.Sign(numFloat);int numDoubleSign = Math.Sign(numDouble);int numDecimalSign = Math.Sign(numDecimal);// Print the resultsConsole.WriteLine($"Math.Sign({numInt}) = {numIntSign}");Console.WriteLine($"Math.Sign({numFloat}) = {numFloatSign}");Console.WriteLine($"Math.Sign({numDouble}) = {numDoubleSign}");Console.WriteLine($"Math.Sign({numDecimal}) = {numDecimalSign}");}}
This example outputs the following:
Math.Sign(-50) = -1Math.Sign(0) = 0Math.Sign(2.7) = 1Math.Sign(-0.01) = -1
Codebyte Example
In this example, a random number between -100 and 100 is generated, and its sign is determined using the Math.Sign() method. A message is printed to indicate whether the random number is negative, positive, or zero:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn C# on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn Microsoft's popular C# programming language, used to make websites, mobile apps, video games, VR, and more.
- Beginner Friendly.15 hours