Converting a float into a timespan
So, you're looking for... TimeSpan.FromHours(double)?
The documentation is your friend.
You want the FromHours
method.
This takes a double (rather than a float) and returns a TimeSpan
:
double hours = 1.5;
TimeSpan interval = TimeSpan.FromHours(hours);
To get the total hours from a TimeSpan
use the TotalHours
property:
TimeSpan interval = new TimeSpan(1, 15, 42, 45, 750);
double hours = interval.TotalHours;