# Math.Truncate メソッド

## オーバーロード

 Truncate(Decimal) 指定した 10 進数の整数部を計算します。Calculates the integral part of a specified decimal number. Truncate(Double) 指定した倍精度浮動小数点数の整数部を計算します。Calculates the integral part of a specified double-precision floating-point number.

## Truncate(Decimal)

public:
static System::Decimal Truncate(System::Decimal d);
public static decimal Truncate (decimal d);
static member Truncate : decimal -> decimal
Public Shared Function Truncate (d As Decimal) As Decimal

d
Decimal

#### 戻り値

d の整数部。つまり、小数部の桁を破棄した後に残る数値。The integral part of d; that is, the number that remains after any fractional digits have been discarded.

### 例

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))

### 注釈

Truncate は、d を0方向の最も近い整数に丸めます。Truncate rounds d to the nearest integer towards zero.

## Truncate(Double)

public:
static double Truncate(double d);
public static double Truncate (double d);
static member Truncate : double -> double
Public Shared Function Truncate (d As Double) As Double

d
Double

#### 戻り値

d の整数部。つまり、小数部の桁を破棄した後に残る数値 (次の表にリストされている値のいずれか)。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.

### 例

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))

### 注釈

Truncate は、d を0方向の最も近い整数に丸めます。Truncate rounds d to the nearest integer towards zero.

Visual Basic 15.8 以降では、Truncate メソッドから返された値を任意の整数変換関数に渡す場合、または Truncate によって返される double 値がOption Strictが Off に設定されている整数に自動的に変換される場合は、倍精度整数変換のパフォーマンスが最適化されます。Starting with Visual Basic 15.8, the performance of Double-to-integer conversion is optimized if you pass the value returned by the Truncate method to the any of the integral conversion functions, or if the Double value returned by Truncate is automatically converted to an integer with Option Strict set to Off. この最適化によって、コードをより速く実行できます。大きい数値の整数型への変換を行うコードでは、最大で 2 倍速くなります。This optimization allows code to run faster -- up to twice as fast for code that does a large number of conversions to integer types. 次の例は、このように最適化された変換を示しています。The following example illustrates such an optimized conversion:

Dim d As Double = 164.7194
Dim i As Integer = CInt(Math.Truncate(d))     ' Result: 164