Decimal - ToSByte
Converts the value of the specified to the equivalent 8-bit signed integer.
static string formatter = "{0,30}{1,23}"; public static void Main() { decimal[] values = { 123m, new Decimal(78000, 0, 0, false, 3), 78.999m, 255.999m, 256m, 127.999m, 128m, -0.999m, -1m, -128.999m, -129m }; Console.WriteLine(formatter, "Decimal value", "SByte"); Console.WriteLine(formatter, "----------------", "------"); foreach (var value in values) { try { // C# Extension Method: Decimal - ToSByte sbyte number = value.ToSByte(); Console.WriteLine(formatter, value, number); } catch (OverflowException e) { Console.WriteLine(formatter, e.GetType().Name, value); } } }
View Source
using System; public static partial class Extensions { /// <summary> /// Converts the value of the specified to the equivalent 8-bit signed integer. /// </summary> /// <param name="value">The decimal number to convert.</param> /// <returns>An 8-bit signed integer equivalent to .</returns> public static SByte ToSByte(this Decimal value) { return Decimal.ToSByte(value); } }