-1

Why I get incorrect result.(for example n=3.83 I expect temp=0.83 but when trace my code temp=0.83000000000000007) notice:temp,m and n are double.

n = double.Parse(Console.ReadLine());
        m = Math.Floor(n);
        Console.WriteLine(m);
        temp = n - m;
Subzero
  • 19
  • 3

1 Answers1

-1

The reason is precision of double. The store numbers only approximately. Therefore, you can have difference in lower digits. Usually it's not critical, but bad when:

  • You want an exact answer.
  • The error accumulates.