C# Math Sign(Decimal)

Description

Math Sign(Decimal) returns a value indicating the sign of a decimal number.

Syntax

Math.Sign(Decimal) has the following syntax.


public static int Sign(
  decimal value
)

Parameters

Math.Sign(Decimal) has the following parameters.

  • value - A signed decimal number.

Returns

Math.Sign(Decimal) method returns A number that indicates the sign of value, as shown in the following table. Return value Meaning -1 value is less than zero. 0 value is equal to zero. 1 value is greater than zero.

Example

The following example demonstrates how to use the Sign(Decimal) method to determine the sign of a Decimal value and display it to the console.


using System;/* w  w w  . j a v  a  2s .c om*/

class Sample 
{
    public static void Main() 
    {
        Decimal  xDecimal1 = -7m;
    
        Console.WriteLine(Test(Math.Sign(xDecimal1)));
    }

    public static String Test(int compare)
    {
        if (compare == 0) 
           return "equal to";
        else if (compare < 0)  
            return "less than";
        else  
            return "greater than";
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version