Why does 1070 % 21,4 gives a different result in the windows calculator and .net?
(.Net result is 7.1....)
The result should always be 0. I understand a difference with large numbers, but these small numbers should work, IMHO.
Thanks a lot!
Why does 1070 % 21,4 gives a different result in the windows calculator and .net?
(.Net result is 7.1....)
The result should always be 0. I understand a difference with large numbers, but these small numbers should work, IMHO.
Thanks a lot!
 
    
    Its all in the docs for the % operator. Its floating point remainder, not modulo. If you want something compatible with Calculator use this function
For example:
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} (.IEEE) = {ieeeRemainder,18}");
   Console.WriteLine($"{formula,-16} (.NET)  = {remainder,18}");
}
