How to convert value doublein time? for example, I have this value double
val = 0.00295692867015203and I want to return it 4:15.
I did a lot of research and didn't find a solution that worked! Here is a function that I tried too, but returns 00:00:00:
ConvertFromDecimalToDDHHMM(Convert.ToDecimal(val));
public string ConvertFromDecimalToDDHHMM(decimal dHours) {
try {
decimal hours = Math.Floor(dHours);
decimal minutes = (dHours - hours) * 60.0M;
int D = (int)Math.Floor(dHours / 24);
int H = (int)Math.Floor(hours - (D * 24));
int M = (int)Math.Floor(minutes);
string timeFormat = String.Format("{0:00}:{1:00}:{2:00}", D, H, M);
return timeFormat;
}
catch (Exception) {
throw;
}
}
I use C#and ASP.NET. I would appreciate any advice.
source
share