# Thread: converting decimals to minutes

1. Registered User
Join Date
Jul 2004
Posts
34

## Unanswered: converting decimals to minutes

Hi, Im trying to convert a time field thats in decimals to standard minutes...

Example: I have a field that has a value in hours.hundredths
125.92--i want to convert to-->125:55
254.50--i want to convert to-->254:30

I need a formula that looks at the last 2 numbers behind the decimal and divides it by 60...

Any help would be greatly appreciated...

Thanks,
Jared

2. Registered User
Join Date
Jan 2005
Location
Avon Lake, OH
Posts
112
Hi Jared,

If the time field is a float (tblHours.fHours), you can try this:

Local NumberVar iHours;
Local NumberVar iMinutes;

iHours := Int({tblHours.fHours});
iMinutes := 60.0 * ({tblHours.fHours} - iHours);

// Use Right(..., 2) to pad minutes with zeroes
ToText(iHours, 0) + ":" + Right("00" + ToText(iMinutes, 0), 2);

If the time field is a string (tblHours.strHours), you can try this:

Local NumberVar iDecPoint;
Local NumberVar iLength;
Local NumberVar iMinutes;
Local StringVar strHours;
Local StringVar strMinutes;

// Handle blank string
iLength := Len({tblHours.strHours});
If iLength = 0 Then
(
strHours := "0";
strMinutes := "00"
)
Else
(
iDecPoint := Instr({tblHours.strHours}, ".");
If iDecPoint = 0 Then
(
strHours := {tblHours.strHours};
strMinutes := "00"
)
Else
(
strHours := Left({tblHours.strHours}, iDecPoint - 1);
strMinutes := Right({tblHours.strHours}, iLength - iDecPoint);
strMinutes := Left(strMinutes + "00", 2);
//Ensures that .5 is treated as .50
iMinutes := (ToNumber(strMinutes)) * 0.6;
strMinutes := Right("00" + ToText(iMinutes, 0), 2);
If Len(StrHours) = 0 Then
strHours := "0";
)
);
strHours + ":" + strMinutes;

Best regards,

Barry

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•