Decimal.Remainder(Decimal, Decimal) Metoda
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Vypočítá zbytek po vydělení dvou Decimal hodnot.
public:
static System::Decimal Remainder(System::Decimal d1, System::Decimal d2);
public static decimal Remainder (decimal d1, decimal d2);
static member Remainder : decimal * decimal -> decimal
Public Shared Function Remainder (d1 As Decimal, d2 As Decimal) As Decimal
- d1
- Decimal
Dividenda.
- d2
- Decimal
Dělitel.
Zbytek po dělení d1
pomocí d2
.
d2
je nula.
Vrácená hodnota je menší než Decimal.MinValue nebo větší než Decimal.MaxValue.
Následující příklad používá metodu Remainder k výpočtu zbytku v řadě operací dělení.
using System;
public class Example
{
public static void Main()
{
// Create parallel arrays of Decimals to use as the dividend and divisor.
Decimal[] dividends = { 79m, 1000m, -1000m, 123m, 1234567800000m,
1234.0123m };
Decimal[] divisors = { 11m, 7m, 7m, .00123m, 0.12345678m, 1234.5678m };
for (int ctr = 0; ctr < dividends.Length; ctr++)
{
Decimal dividend = dividends[ctr];
Decimal divisor = divisors[ctr];
Console.WriteLine("{0:N3} / {1:N3} = {2:N3} Remainder {3:N3}", dividend,
divisor, Decimal.Divide(dividend, divisor),
Decimal.Remainder(dividend, divisor));
}
}
}
// The example displays the following output:
// 79.000 / 11.000 = 7.182 Remainder 2.000
// 1,000.000 / 7.000 = 142.857 Remainder 6.000
// -1,000.000 / 7.000 = -142.857 Remainder -6.000
// 123.000 / 0.001 = 100,000.000 Remainder 0.000
// 1,234,567,800,000.000 / 0.123 = 10,000,000,000,000.000 Remainder 0.000
// 1,234.012 / 1,234.568 = 1.000 Remainder 1,234.012
open System
// Create parallel lists of Decimals to use as the dividend and divisor.
let dividends =
[ 79m; 1000m; -1000m; 123m; 1234567800000m; 1234.0123m ]
let divisors =
[ 11m; 7m; 7m; 0.00123m; 0.12345678m; 1234.5678m ]
for i = 0 to dividends.Length - 1 do
let dividend = dividends[i]
let divisor = divisors[i]
printfn $"{dividend:N3} / {divisor:N3} = {Decimal.Divide(dividend, divisor):N3} Remainder {Decimal.Remainder(dividend, divisor):N3}"
// The example displays the following output:
// 79.000 / 11.000 = 7.182 Remainder 2.000
// 1,000.000 / 7.000 = 142.857 Remainder 6.000
// -1,000.000 / 7.000 = -142.857 Remainder -6.000
// 123.000 / 0.001 = 100,000.000 Remainder 0.000
// 1,234,567,800,000.000 / 0.123 = 10,000,000,000,000.000 Remainder 0.000
// 1,234.012 / 1,234.568 = 1.000 Remainder 1,234.012
Module Example
Sub Main( )
' Create parallel arrays of Decimals to use as the dividend and divisor.
Dim dividends() As Decimal = { 79d, 1000d, -1000d, 123d, 1234567800000d,
1234.0123d }
Dim divisors() As Decimal = { 11d, 7d, 7d, .00123d, 0.12345678d,
1234.5678d }
For ctr As Integer = 0 To dividends.Length - 1
Dim dividend As Decimal = dividends(ctr)
Dim divisor As Decimal = divisors(ctr)
Console.WriteLine("{0:N3} / {1:N3} = {2:N3} Remainder {3:N3}", dividend,
divisor, Decimal.Divide(dividend, divisor),
Decimal.Remainder(dividend, divisor))
Next
End Sub
End Module
' The example displays the following output:
' 79.000 / 11.000 = 7.182 Remainder 2.000
' 1,000.000 / 7.000 = 142.857 Remainder 6.000
' -1,000.000 / 7.000 = -142.857 Remainder -6.000
' 123.000 / 0.001 = 100,000.000 Remainder 0.000
' 1,234,567,800,000.000 / 0.123 = 10,000,000,000,000.000 Remainder 0.000
' 1,234.012 / 1,234.568 = 1.000 Remainder 1,234.012
Produkt | Verze |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |
Zpětná vazba k produktu .NET
.NET je open source projekt. Vyberte odkaz pro poskytnutí zpětné vazby: