TimeSpan.FromMilliseconds seems not to work consistently RRS feed

  • Question

  • Dear MS Team,

      In C# if I create a TimeSpan based on the number of milliseconds, sometimes the length of the interval is not correct.

      Is this intentional? If so, can you provide the rationale behind the behaviour?

      The sample code would be 

    var ticks = TimeSpan.FromMilliseconds (315537897599999).Ticks

      Based on the fact, that a millisecond is equivalent with 10000 ticks, I would expect this to return 3155378975999990000, but instead the value of ticks will be 3155378975999989760.

       If the number of milliseconds is two orders of magnitude smaller, then this issue does not appear anymore.

       Timespans can be created based on ticks, without issue for this size.

    Thanks in advance,

      Sándor Kolumbán

    Friday, November 27, 2020 7:48 AM

All replies