I am trying to convert the time represented in double to something like 23.40 , which means 23 hours 40 minutes using the following method:
private TimeSpan DoubleToTimeSpan(double time) { double hour = Math.Floor(time); double minute = (time - hour) * 100d; TimeSpan ts = new TimeSpan((int)hour, (int)minute, 0); return ts; }
When testing several times, for example 23.40 :
Console.WriteLine(DoubleToTimeSpan(23.40));
It shows 23:39:00 , the whole minute was stolen by the system! Where is my minute?
Note : I know about TimeSpan.FromHours , this does not help me because this method counts minutes as a percentage, so 23.40 is 23 hours and 40% of the hour, which is 23:24:00 .
user915331
source share