Math.Truncate Math.Truncate Math.Truncate Method

Definition

Calculates the integral part of a number.

Overloads

Truncate(Decimal) Truncate(Decimal) Truncate(Decimal)

Calculates the integral part of a specified decimal number.

Truncate(Double) Truncate(Double) Truncate(Double)

Calculates the integral part of a specified double-precision floating-point number.

Remarks

The number is rounded to the nearest integer towards zero.

Truncate(Decimal) Truncate(Decimal) Truncate(Decimal)

Calculates the integral part of a specified decimal number.

public:
 static System::Decimal Truncate(System::Decimal d);
public static decimal Truncate (decimal d);
Public Shared Function Truncate (d As Decimal) As Decimal
Parameters
d
Decimal Decimal Decimal

A number to truncate.

Returns

The integral part of d; that is, the number that remains after any fractional digits have been discarded.

Examples

The following example calls the Truncate(Decimal) method to truncate both a positive and a negative Decimal value.

decimal decimalNumber;

decimalNumber = 32.7865m;
// Displays 32
Console.WriteLine(Math.Truncate(decimalNumber));

decimalNumber = -32.9012m;
// Displays -32         
Console.WriteLine(Math.Truncate(decimalNumber));
Dim decimalNumber As Decimal

decimalNumber = 32.7865d
' Displays 32      
Console.WriteLine(Math.Truncate(decimalNumber))

decimalNumber = -32.9012d
' Displays -32
Console.WriteLine(Math.Truncate(decimalNumber))  

Remarks

Truncate rounds d to the nearest integer towards zero.

See Also

Truncate(Double) Truncate(Double) Truncate(Double)

Calculates the integral part of a specified double-precision floating-point number.

public:
 static double Truncate(double d);
public static double Truncate (double d);
Public Shared Function Truncate (d As Double) As Double
Parameters
d
Double Double Double

A number to truncate.

Returns

The integral part of d; that is, the number that remains after any fractional digits have been discarded, or one of the values listed in the following table.

d Return value
NaNNaN
NegativeInfinityNegativeInfinity
PositiveInfinityPositiveInfinity

Examples

The following example calls the Truncate(Double) method to truncate both a positive and a negative Double value.

double floatNumber;

floatNumber = 32.7865;
// Displays 32      
Console.WriteLine(Math.Truncate(floatNumber));

floatNumber = -32.9012;
// Displays -32       
Console.WriteLine(Math.Truncate(floatNumber));
Dim floatNumber As Double

floatNumber = 32.7865
' Displays 32      
Console.WriteLine(Math.Truncate(floatNumber)) 

floatNumber = -32.9012
' Displays -32
Console.WriteLine(Math.Truncate(floatNumber))

Remarks

Truncate rounds d to the nearest integer towards zero.

See Also

Applies to