Decimal.ToSByte() Method in C#


The Decimal.ToSByte() method in C# is used to convert the value of the specified Decimal to the equivalent 8-bit signed integer.

Syntax

Following is the syntax −

public static sbyte ToSByte (decimal val);

Above, Val is the decimal number to convert.

Example

Let us now see an example to implement the Decimal.ToSByte() method −

using System;
public class Demo {
   public static void Main(){
      Decimal val = 97.567m;
      Console.WriteLine("Decimal value = "+val);
      sbyte res = Decimal.ToSByte(val);
      Console.WriteLine("SByte value = "+res);
   }
}

Output

This will produce the following output −

Decimal value = 97.567
SByte value = 97

Example

Let us now see another example to implement the Decimal.ToSByte() method −

using System;
public class Demo {
   public static void Main(){
      Decimal val = 0.001m;
      Console.WriteLine("Decimal value = "+val);
      sbyte res = Decimal.ToSByte(val);
      Console.WriteLine("SByte value = "+res);
   }
}

Output

This will produce the following output −

Decimal value = 0.001
SByte value = 0
raja
Published on 06-Nov-2019 08:00:42
Advertisements