Converting minutes to tenths

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
sxpapado
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10
Joined: Tue Oct 04, 2011 5:54 pm

Converting minutes to tenths

Post by sxpapado » Tue Oct 04, 2011 6:01 pm

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

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Converting minutes to tenths

Post by mwieder » Tue Oct 04, 2011 6:39 pm

put round(tSeconds / 6)

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10320
Joined: Wed May 06, 2009 2:28 pm

Re: Converting minutes to tenths

Post by dunbarx » Wed Oct 05, 2011 2:37 am

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

sxpapado
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10
Joined: Tue Oct 04, 2011 5:54 pm

Re: Converting minutes to tenths

Post by sxpapado » Wed Oct 05, 2011 4:39 am

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.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Converting minutes to tenths

Post by bn » Wed Oct 05, 2011 7:09 am

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10320
Joined: Wed May 06, 2009 2:28 pm

Re: Converting minutes to tenths

Post by dunbarx » Wed Oct 05, 2011 2:50 pm

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

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Converting minutes to tenths

Post by bn » Wed Oct 05, 2011 3:04 pm

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10320
Joined: Wed May 06, 2009 2:28 pm

Re: Converting minutes to tenths

Post by dunbarx » Wed Oct 05, 2011 3:35 pm

Bernd.

Shucks. (An Americanism)

High praise indeed coming from someone like you.

Craig

sxpapado
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10
Joined: Tue Oct 04, 2011 5:54 pm

Re: Converting minutes to tenths

Post by sxpapado » Wed Oct 05, 2011 7:02 pm

Wow, thanks guys. This is still new to me but this makes sense.

Post Reply