Truncate Method

# Decimal.Truncate Method

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

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

## Syntax

```'Declaration
Public Shared Function Truncate ( _
d As Decimal _
) As Decimal
```

#### Parameters

d
Type: System.Decimal
A Decimal to truncate.

#### Return Value

Type: System.Decimal
The Decimal result of d rounded toward zero, to the nearest whole number.

## Remarks

This method rounds d toward zero, to the nearest whole number, which corresponds to discarding any digits after the decimal point.

## Examples

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

```
' Example of the Decimal.Negate, Decimal.Floor, and Decimal.Truncate
' methods.

Module Example

Const dataFmt As String = "{0,-30}{1,26}"

' Display Decimal parameters and their product, quotient, and
' remainder.
Sub ShowDecimalFloorNegTrunc(ByVal outputBlock As System.Windows.Controls.TextBlock, ByVal Argument As Decimal)

outputBlock.Text &= vbCrLf
outputBlock.Text &= String.Format(dataFmt, "Decimal Argument", Argument) & vbCrLf
outputBlock.Text &= String.Format(STring.Format(dataFmt, _
"Decimal.Negate( Argument )", _
Decimal.Negate(Argument))) & vbCrLf
outputBlock.Text &= String.Format(dataFmt, _
"Decimal.Floor( Argument )", _
Decimal.Floor(Argument)) & vbCrLf
outputBlock.Text &= String.Format(dataFmt, _
"Decimal.Truncate( Argument )", _
Decimal.Truncate(Argument)) & vbCrLf
End Sub

Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
outputBlock.Text &= "This example of the " & vbCrLf & _
"  Decimal.Negate( Decimal ), " & vbCrLf & _
"  Decimal.Floor( Decimal ), and " & vbCrLf & _
"  Decimal.Truncate( Decimal ) " & vbCrLf & _
"methods generates the following output." & vbCrLf

' Create pairs of Decimal objects.
ShowDecimalFloorNegTrunc(outputBlock, 0D)
ShowDecimalFloorNegTrunc(outputBlock, 123.456D)
ShowDecimalFloorNegTrunc(outputBlock, -123.456D)
ShowDecimalFloorNegTrunc(outputBlock,  _
New Decimal(1230000000, 0, 0, True, 7))
ShowDecimalFloorNegTrunc(outputBlock, -9999999999.9999999999D)
End Sub
End Module

' This example of the
'   Decimal.Negate( Decimal ),
'   Decimal.Floor( Decimal ), and
'   Decimal.Truncate( Decimal )
' methods generates the following output.
'
' Decimal Argument                                       0
' Decimal.Negate( Argument )                             0
' Decimal.Floor( Argument )                              0
' Decimal.Truncate( Argument )                           0
'
' Decimal Argument                                 123.456
' Decimal.Negate( Argument )                      -123.456
' Decimal.Floor( Argument )                            123
' Decimal.Truncate( Argument )                         123
'
' Decimal Argument                                -123.456
' Decimal.Negate( Argument )                       123.456
' Decimal.Floor( Argument )                           -124
' Decimal.Truncate( Argument )                        -123
'
' Decimal Argument                            -123.0000000
' Decimal.Negate( Argument )                   123.0000000
' Decimal.Floor( Argument )                           -123
' Decimal.Truncate( Argument )                        -123
'
' Decimal Argument                  -9999999999.9999999999
' Decimal.Negate( Argument )         9999999999.9999999999
' Decimal.Floor( Argument )                   -10000000000
' Decimal.Truncate( Argument )                 -9999999999

```

## Version Information

#### Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show: