Math problem
Geoff Canyon Rev
gcanyon+rev at gmail.com
Fri Feb 17 12:20:57 EST 2012
Obviously you could do this inline, but then it wouldn't be reusable. I'd
go with a function:
function roundUp x,i -- rounds x up to the next i
return ((x - .00001) div i + 1) * i
end roundUp
function test T1,T2
-- returns the difference between two times in seconds
-- rounded up to the next 15 minutes
convert T1 to seconds
convert T2 to seconds
put roundUp(T2 - T1,900) into D
return D
end test
The roundUp function will take any two numbers and return the first rounded
up to the nearest increment of the second. Obviously the .0000001 aspect is
a limitation -- if I were being particular I suppose I'd use an if
statement there, but you wanted math and this seems good enough. So:
put roundUp(60,10) -- puts 60
put roundUp(61,10) -- puts 70
Having this function makes it easy to do the time math you were talking
about, as shown in the test function.
gc
More information about the use-livecode
mailing list