Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to convert a value behind the decimal to seconds? 2

Status
Not open for further replies.

ynott

Technical User
Sep 26, 2000
49
US
I have a report that will say something like 15.75 or 6.04567 for a time value. With that said, 15.75 equates to 15 minutes and 45 seconds (.75).

What formula, if any, would I use to create something that replaces 15.75 with two values:

Minutes = 15
Seconds = 45

Please keep in mind that I don't want to round up 15 to 16 for that separate value and something like 45.6795 seconds would be okay.

TIA
 
For this kind of thing I generally use the remainder function and multiply the originally number out before I go after the remainder.

Failing that being available, I use a formula that takes the first number and subtracts a 'fix' or 'int' of the second number. Fix is a function usually available that returns the number without the decimal (int is sometimes exactly the same). Look through your help file for each of these.

It will look like ( {numberfield}-fix({numberfield}) ) * 60 to get the seconds.

So in your example the 15.75 would first become .75 and then multiply by 60 to give 45.

As I recall, the difference between Int and Fix had to do with negative numbers, where INT would give you the next lower number, and FIX would give you the next higher number.

So INT(-4.5) = -5
FIX(-4.5) = -4

but your help file will let you know. Since you aren't likely to have negative seconds the difference may not matter.

Oh, you did ask if this could be done in one formula. Yes, although it is easier to follow if you do it in two. If you had to do it in one formula you would have to turn the numbers into text:

"Minutes: " + totext(fix({numberfield)) + " " + "Seconds: " + totext(( {numberfield}-fix({numberfield}) ) * 60)



Although I wouldn't go to that trouble. I'd make a formula for minutes, another for seconds, plunk a text field box onto the report and drag the two formulas down, then put the text and stuff around them.

Scott.
 
Create two formulae

@Seconds

remainder({fieldname},1)*60

where fieldname is the filed or formula containing your 15.75. The above will return 45.

@Minutes
int({fieldname})

You can convert these to text if you wish and concatenate with the words seconds and minutes.

eg "Seconds " & totext((remainder({fieldname},1)*60),0)

Ian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top