ExtensionMethod.NET Home of 875 C#, Visual Basic, F# and Javascript extension methods

decimalToTime

Convert decimal in string Timeformat (hh:mm)

Source

public static string decimalToTime(this decimal time)
{
    
    string Hours = Math.Truncate(time).ToString();
    string Minuten = Math.Round((time - Math.Truncate(time))*60).ToString();
    return Hours + ":" + Minuten;
}

Example

Convert decimal in string Timeformat (hh:mm):
Examples:
19.5 to 19:30
20.166666666666666666666666667 to 19:70
12.75 to 12:45

Author: Andreas Seibel

Submitted on: 26 mei 2015

Language: C#

Type: string

Views: 4191