C# Decimal Truncate

Description

Decimal Truncate returns the integral digits of the specified Decimal; any fractional digits are discarded.

Syntax

Decimal.Truncate has the following syntax.


public static decimal Truncate(
  decimal d
)

Parameters

Decimal.Truncate has the following parameters.

  • d - The decimal number to truncate.

Returns

Decimal.Truncate method returns The result of d rounded toward zero, to the nearest whole number.

Example

The following code example uses the Truncate method to discard the fractional digits of Decimal values.


using System;// w w  w.j  ava  2s.c  o m

class MainClass
{
    public static void Main( )
    {
        Console.WriteLine(decimal.Truncate( 123.456M ) );
    }
}

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