Code to convert work hours wraps to 24 hours?

anykan

New Member
I have some code which takes for example, 27:30 (27 hours 30 minutes) and converts it to a decimal like 27.5. I have another function that does the opposite.\[code\] public class Time { public static string Hours(decimal d) { return TimeSpan.FromHours((double)(d + 0.005M)).ToString("h\\:mm"); } public static decimal Hours(string s) { decimal r; if (decimal.TryParse(s, out r)) return r; return (decimal)TimeSpan.Parse(s).TotalHours + 0.005M; } }\[/code\]The problem is that the conversion from decimal to string seems to wrap to 24 hours. If I give it 30.0 it gives me 6:00 which is wrong. It should be 30:00What could I do to avoid the wrap?Thanks
 
Back
Top