十进制的 C# 中的 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
广告