Page 1 of 1

Converting minutes to tenths

Posted: Tue Oct 04, 2011 6:01 pm
by sxpapado
Hi all,

is there a script for converting minutes to tenths based upon this data below? I reviewed the dictionary but didn't come up with any statements I could figure out. Thanks


MINUTES TENTHS
01 .0
02 .0
03 .1
04 .1
05 .1
06 .1
07 .1
08 .1
09 .2
10 .2
11 .2
12 .2
13 .2
14 .2
15 .3
16 .3
17 .3
18 .3
19 .3
20 .3
21 .4
22 .4
23 .4
24 .4
25 .4
26 .4
27 .5
28 .5
29 .5
30 .5
MINUTES TENTHS
31 .5
32 .5
33 .6
34 .6
35 .6
36 .6
37 .6
38 .6
39 .7
40 .7
41 .7
42 .7
43 .7
44 .7
45 .8
46 .8
47 .8
48 .8
49 .8
50 .8
51 .9
52 .9
53 .9
54 .9
55 .9
56 .9
57 1.
58 1.
59 1.
00 .0

Re: Converting minutes to tenths

Posted: Tue Oct 04, 2011 6:39 pm
by mwieder
put round(tSeconds / 6)

Re: Converting minutes to tenths

Posted: Wed Oct 05, 2011 2:37 am
by dunbarx
Hi.

Do you mean that if you have 3.1 minutes, you want to derive 19 tenths?

If so

Code: Select all

on mouseUp
   get line 2 of fld 1 --just one line of your field data
   answer minutesTotenths(it)
end mouseUp

function minutestotenths var
   set itemdel to "."
   return item 1 of var * 6 + item 2 of var
end minutestotenths
:

Can you expand this with a repeat loop to handle the whole list? You might also try this with the offset function, a favorite of many.

or am I way off here?

Craig Newman

Re: Converting minutes to tenths

Posted: Wed Oct 05, 2011 4:39 am
by sxpapado
Thanks for the reply's. What I was getting at is if you have 2hours and 44 minutes (2:44) that should convert to 2.7 and not 2.8 as per the table.

I think the round command might work here. I have to try it.

Re: Converting minutes to tenths

Posted: Wed Oct 05, 2011 7:09 am
by bn
Hi sxpapado,

the table assumes 59 minutes.

if you do a field with 2 fields and put the numbers 0 through 59 into field 1 and this code into a button

Code: Select all

on mouseUp
   put field 1 into tData
   set the numberformat to "0.0"
      repeat for each line aLine in tData
         put aLine & tab & tensOfMinutes(aLIne) & cr after tCollect
      end repeat
      delete last char of tCollect
      put tCollect into field 2
end mouseUp

function tensOfMinutes pMinutes
   put 100/59 into tPart
   return ( round((pMinutes * tPart)*10)/1000)
end tensOfMinutes
this gives me the values of your table. There might be a smarter way to do this. I had to multiply by 10 and divide by 1000 to get the rounding right.

Kind regards

Bernd

Re: Converting minutes to tenths

Posted: Wed Oct 05, 2011 2:50 pm
by dunbarx
Try this. I chose your test example of "2:44":

Code: Select all

on mouseUp 
   put "2:44" into var
 answer timeToDecimal(var)
end mouseUp

function timeToDecimal var
   set the itemdel to ":"
   put item 2 of var into tfraction
   return item 1 of var +round(tFraction / 60,1)
end timeToDecimal
Craig Newman

Re: Converting minutes to tenths

Posted: Wed Oct 05, 2011 3:04 pm
by bn
Hi Craig,

that is very nice. A lot cleaner than what I came up with. It had to be easier than what I did. I shouldn't venture into math... :)

Kind regards

Bernd

Re: Converting minutes to tenths

Posted: Wed Oct 05, 2011 3:35 pm
by dunbarx
Bernd.

Shucks. (An Americanism)

High praise indeed coming from someone like you.

Craig

Re: Converting minutes to tenths

Posted: Wed Oct 05, 2011 7:02 pm
by sxpapado
Wow, thanks guys. This is still new to me but this makes sense.