C#中的Decimal.Remainder()方法
C#中的Decimal.Remainder()方法用于在除以两个Decimal值之后计算余数。
语法
以下是语法-
public static decimal Remainder (decimal val1, decimal val2);
上面的val1是除数,而val2是除数。
示例
现在让我们看一个实现Decimal.Remainder()方法的示例-
using System; public class Demo { public static void Main(){ Decimal val1 = 45.15m; Decimal val2 = 15.15m; Console.WriteLine("Decimal 1 = "+val1); Console.WriteLine("Decimal 2 = "+val2); Console.WriteLine("After Division = "+(Decimal.Divide(val1,val2))); Console.WriteLine("Remainder = "+(Decimal.Remainder(val1,val2))); } }
输出结果
这将产生以下输出-
Decimal 1 = 45.15 Decimal 2 = 15.15 After Division = 2.9801980198019801980198019802 Remainder = 14.85
示例
现在让我们来看另一个实现Decimal.Remainder()方法的示例-
using System; public class Demo { public static void Main(){ Decimal val1 = 1.00m; Decimal val2 = 1.00m; Console.WriteLine("Decimal 1 = "+val1); Console.WriteLine("Decimal 2 = "+val2); Console.WriteLine("After Division = "+(Decimal.Divide(val1,val2))); Console.WriteLine("Remainder = "+(Decimal.Remainder(val1,val2))); } }
输出结果
这将产生以下输出-
Decimal 1 = 1.00 Decimal 2 = 1.00 After Division = 1 Remainder = 0.00