Converting decimal values to hours in C#

Posted by Sheonarayan under C# category on | Points: 40 | Views : 1552
To convert decimal values to hours, use below function.
public static string ConvertDecimalToHours(decimal hours)
TimeSpan tt = TimeSpan.FromHours(Decimal.ToDouble(hours));
return tt.Hours.ToString("00") + ":" + tt.Minutes.ToString("00");

Use this function like

This will output result as "03:45".

If above function doesn't work (if your hours values are more than 24) then use


Comments or Responses

Login to post response