Perhaps you can try this, it works with doubles but you can convert decimal to double.
class Program
{
static void Main(string[] args)
{
double DecNum = 13.573451;
string TheTime = MakeTimeString(DecNum);
Console.WriteLine(TheTime);
DecNum = 1.25;
TheTime = MakeTimeString(DecNum);
Console.WriteLine(TheTime);
Console.ReadKey(); // hold console until a key is pressed
}
static string MakeTimeString(double num)
{
double hours = Math.Floor(num); //take integral part
double minutes = (num - hours) * 60.0; //multiply fractional part with 60
//double seconds = (minutes - Math.Floor(minutes)) * 60.0; //add if you want seconds
int H = (int)Math.Floor(hours);
int M = (int)Math.Floor(minutes);
//int S = (int)Math.Floor(seconds); //add if you want seconds
return H.ToString() + ":" + M.ToString(); //+":" + S.ToString(); //add if you want seconds
}
}
Reputation Points: 2035
Solved Threads: 645
Senior Poster
Offline 3,740 posts
since Oct 2008