İngilizce dilinde oku

Aracılığıyla paylaş


MidpointRounding Sabit listesi

Tanım

Matematiksel yuvarlama yöntemlerinin bir sayıyı yuvarlarken kullanması gereken stratejiyi belirtir.

C#
public enum MidpointRounding
C#
[System.Runtime.InteropServices.ComVisible(true)]
public enum MidpointRounding
Devralma
MidpointRounding
Öznitelikler

Alanlar

Name Değer Description
AwayFromZero 1

En yakın sayıya yuvarlama stratejisi ve bir sayı diğer iki sayının ortasında olduğunda sıfırdan uzak olan en yakın sayıya doğru yuvarlanır.

ToEven 0

En yakın sayıya yuvarlama stratejisi ve bir sayı diğer iki sayı arasında ortalandığında, en yakın çift sayıya doğru yuvarlanir.

ToNegativeInfinity 3

Aşağı yönlü yuvarlama stratejisi, sonuca en yakın ve sonsuz kesin sonuçtan büyük değil.

ToPositiveInfinity 4

Yukarı yönlü yuvarlama stratejisi, sonuca en yakın ve sonsuz kesin sonuca daha az değil.

ToZero 2

Sıfıra doğru yönlü yuvarlama stratejisi, sonuç sonsuz hassas sonuca en yakın ve en büyük değere sahip değildir.

Örnekler

Aşağıdaki örnekte, sabit listesiyle MidpointRounding birlikte yöntemi gösterilmektedirMath.Round:

C#
decimal result;

// Round a positive value using different strategies.
// The precision of the result is 1 decimal place.

result = Math.Round(3.45m, 1, MidpointRounding.ToEven);
Console.WriteLine($"{result} = Math.Round({3.45m}, 1, MidpointRounding.ToEven)");
result = Math.Round(3.45m, 1, MidpointRounding.AwayFromZero);
Console.WriteLine($"{result} = Math.Round({3.45m}, 1, MidpointRounding.AwayFromZero)");
result = Math.Round(3.47m, 1, MidpointRounding.ToZero);
Console.WriteLine($"{result} = Math.Round({3.47m}, 1, MidpointRounding.ToZero)\n");

// Round a negative value using different strategies.
// The precision of the result is 1 decimal place.

result = Math.Round(-3.45m, 1, MidpointRounding.ToEven);
Console.WriteLine($"{result} = Math.Round({-3.45m}, 1, MidpointRounding.ToEven)");
result = Math.Round(-3.45m, 1, MidpointRounding.AwayFromZero);
Console.WriteLine($"{result} = Math.Round({-3.45m}, 1, MidpointRounding.AwayFromZero)");
result = Math.Round(-3.47m, 1, MidpointRounding.ToZero);
Console.WriteLine($"{result} = Math.Round({-3.47m}, 1, MidpointRounding.ToZero)\n");

/*
This code example produces the following results:

3.4 = Math.Round(3.45, 1, MidpointRounding.ToEven)
3.5 = Math.Round(3.45, 1, MidpointRounding.AwayFromZero)
3.4 = Math.Round(3.47, 1, MidpointRounding.ToZero)

-3.4 = Math.Round(-3.45, 1, MidpointRounding.ToEven)
-3.5 = Math.Round(-3.45, 1, MidpointRounding.AwayFromZero)
-3.4 = Math.Round(-3.47, 1, MidpointRounding.ToZero)
*/

Açıklamalar

Bu API hakkında daha fazla bilgi için bkz. MidpointRounding için ek API açıklamaları.

Şunlara uygulanır