本文整理汇总了C#中System.Math.IEEERemainder方法的典型用法代码示例。如果您正苦于以下问题:C# Math.IEEERemainder方法的具体用法?C# Math.IEEERemainder怎么用?C# Math.IEEERemainder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Math
的用法示例。
在下文中一共展示了Math.IEEERemainder方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
public class Example
{
public static void Main()
{
Console.WriteLine($"{"IEEERemainder",35} {"Remainder operator",20}");
ShowRemainders(3, 2);
ShowRemainders(4, 2);
ShowRemainders(10, 3);
ShowRemainders(11, 3);
ShowRemainders(27, 4);
ShowRemainders(28, 5);
ShowRemainders(17.8, 4);
ShowRemainders(17.8, 4.1);
ShowRemainders(-16.3, 4.1);
ShowRemainders(17.8, -4.1);
ShowRemainders(-17.8, -4.1);
}
private static void ShowRemainders(double number1, double number2)
{
var formula = $"{number1} / {number2} = ";
var ieeeRemainder = Math.IEEERemainder(number1, number2);
var remainder = number1 % number2;
Console.WriteLine($"{formula,-16} {ieeeRemainder,18} {remainder,20}");
}
}
输出:
IEEERemainder Remainder operator 3 / 2 = -1 1 4 / 2 = 0 0 10 / 3 = 1 1 11 / 3 = -1 2 27 / 4 = -1 3 28 / 5 = -2 3 17.8 / 4 = 1.8 1.8 17.8 / 4.1 = 1.4 1.4 -16.3 / 4.1 = 0.0999999999999979 -4 17.8 / -4.1 = 1.4 1.4 -17.8 / -4.1 = -1.4 -1.4