Sunday, June 5, 2011

Converting Real Number to TIme

public static str 5 num2Time(real _hours)
{

    int realPart;
    int decimalPart;
    real hours;
    str hoursStr;
    str minStr;
    int decimalLocation;
    str finalMinutes;
    ;
    try
    {
        hours = _hours;
        hoursStr = num2str(hours, 0, 2, 1, 0);
        decimalLocation = strfind(hoursStr, ".", 0, strlen(hoursStr));
        hoursStr = substr(hoursStr, 0, decimalLocation);
        hoursStr = trimString(hoursStr, ["."]);
        minStr = num2str(hours, 0, 2, 1, 0);
        minStr = substr(minStr, decimalLocation, strlen(minStr) - strlen(hoursStr));
        minStr = trimString(minStr, ["."]);
        realPart = str2int(hoursStr);
        decimalPart = str2int(minStr);
        finalMinutes = hoursStr + ":" + (int2str(60 * decimalPart / 100) == "0" ? "00" : int2str(60 * decimalPart / 100));
        return finalMinutes;
    }
    catch
    {
        return num2str(_hours, 0, 2, 1, 0);
    }
}

5 comments: