The Decimal.Truncate()
method in C# is used to return the whole number part of a decimal number, while the fractional part is discarded.
public static decimal Truncate (decimal d);
d
: The decimal value whose integral part we want to return.
// use Systemusing System;// create classclass DecimalToSByte{// main methodstatic void Main(){// create decimal valuesdecimal d1 = 34.5m;decimal d2 = 2.4356345m;decimal d3 = 10.34m;// convert to SByte// and print valueConsole.WriteLine("Decimal Value = {0}, whole number part = {1}",d1,Decimal.Truncate(d1));Console.WriteLine("Decimal Value = {0}, whole number part = {1}",d2,Decimal.Truncate(d2));Console.WriteLine("Decimal Value = {0}, whole number part = {1}",d3,Decimal.Truncate(d3));}}
Truncate()
method on the decimal values and print their results.