Math.Truncate Yöntem

Tanım

Bir sayının integral bölümünü hesaplar.Calculates the integral part of a number.

Aşırı Yüklemeler

Truncate(Decimal)

Belirtilen ondalık sayının integral bölümünü hesaplar.Calculates the integral part of a specified decimal number.

Truncate(Double)

Belirtilen çift duyarlıklı kayan noktalı sayının integral bölümünü hesaplar.Calculates the integral part of a specified double-precision floating-point number.

Açıklamalar

Sayı, sıfıra doğru en yakın tamsayıya yuvarlanır.The number is rounded to the nearest integer towards zero.

Truncate(Decimal)

Belirtilen ondalık sayının integral bölümünü hesaplar.Calculates the integral part of a specified decimal number.

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

Parametreler

d
Decimal

Kesmek için bir sayı.A number to truncate.

Döndürülenler

Decimal

Öğesinin integral bölümü d ; diğer bir deyişle, kesirli rakamlardan sonra kalan sayı atılır.The integral part of d; that is, the number that remains after any fractional digits have been discarded.

Örnekler

Aşağıdaki örnek, Truncate(Decimal) hem pozitif hem de negatif bir değeri kesmek için yöntemini çağırır Decimal .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))  

Açıklamalar

Truncatedsıfıra doğru en yakın tamsayıya yuvarlar.Truncate rounds d to the nearest integer towards zero.

Ayrıca bkz.

Şunlara uygulanır

Truncate(Double)

Belirtilen çift duyarlıklı kayan noktalı sayının integral bölümünü hesaplar.Calculates the integral part of a specified double-precision floating-point number.

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

Parametreler

d
Double

Kesmek için bir sayı.A number to truncate.

Döndürülenler

Double

Öğesinin integral bölümü d ; diğer bir deyişle, herhangi bir kesirli basamak sonra kalan sayı atılır veya aşağıdaki tabloda listelenen değerlerden biri.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 Döndürülen değerReturn value
NaNNaN
NegativeInfinityNegativeInfinity
PositiveInfinityPositiveInfinity

Örnekler

Aşağıdaki örnek, Truncate(Double) hem pozitif hem de negatif bir değeri kesmek için yöntemini çağırır Double .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))

Açıklamalar

Truncatedsıfıra doğru en yakın tamsayıya yuvarlar.Truncate rounds d to the nearest integer towards zero.

Visual Basic 15,8 ' den itibaren, yöntem tarafından döndürülen değeri Truncate integral dönüştürme işlevlerinegeçirirseniz veya tarafından döndürülen Double değeri Truncate otomatik olarak Option Strict kapalı olarak bir tamsayıya dönüştürülürse, Double-Integer dönüştürmenin performansı en iyi duruma getirilir.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. Bu iyileştirme kodun çok daha hızlı bir şekilde çalışmasını sağlar ve tamsayı türlerine çok sayıda dönüştürme yapan kod için hızlı bir şekilde daha hızlı çalışır.This optimization allows code to run faster -- up to twice as fast for code that does a large number of conversions to integer types. Aşağıdaki örnekte, bu tür iyileştirilmiş bir dönüştürme gösterilmektedir:The following example illustrates such an optimized conversion:

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

Ayrıca bkz.

Şunlara uygulanır