Cool. Thanks everyone for your responses, I think I'm good to go.
Marty
Not exactly one line, but this works for all the combinations I could think
of:
function incTo x,i -- increments x to the next i
if i = 0 then
return x
else if x mod i<> 0 and x * i< 0 then
return x
Not exactly one line, but this works for all the combinations I could think
of:
function incTo x,i -- increments x to the next i
if i = 0 then
return x
else if x mod i <> 0 and x * i < 0 then
return x div i * i
else
return x div i * i + i
end if
end incTo
Here's my t
Negative numbers aren't a concern. But I also need to round down in the
same fashion (and would bail out at 0).
Thanks guys,
Marty
Hmm, 0 and negatives aren't handled properly either way, starting to think
the proposed loop method might be the easiest method.
On Sat, Feb 18, 2012 at 5:11 PM, J
I didn't follow all of that other thread, but I think it had some
additional complexity. For the straightforward case of adding to the
value until a multiple of 20, you can just do
put 20*( (i+20) div 20) into i
-- Alex (whose old Fortran habits insist on using 'i' as a variable here
:-)
On
Hmm, 0 and negatives aren't handled properly either way, starting to think
the proposed loop method might be the easiest method.
On Sat, Feb 18, 2012 at 5:11 PM, Joe Lewis Wilkins wrote:
> IN CASE YOU'RE HAVING TROUBLE WITH IT, TRY THIS:
>
> put ?? into theValue
> repeat with theValue = theValue
IN CASE YOU'RE HAVING TROUBLE WITH IT, TRY THIS:
put ?? into theValue
repeat with theValue = theValue+1 to theValue +100
IF theValue mod 20 = 0 THEN EXIT REPEAT
end repeat
put theValue
Joe Wilkins
On Feb 18, 2012, at 3:55 PM, Joe Lewis Wilkins wrote:
> Hi Marty,
>
> Just create a repeat loop t
Isn't this the same problem that Geoff Canyon just solved with a delightfully
opaque one line solution in a recent thread:
function roundUp x,i -- rounds x up to the next i
return x div i * i + item itemoffset((x mod i > 0),"true,false") of (i,0)
end roundUp
On Feb 18, 2012, at 3:39 PM, Marty K
My way doesn't work for 0 so ignore it and go with Geoff
On Sat, Feb 18, 2012 at 5:06 PM, Ken Corey wrote:
> On 18/02/2012 23:39, Marty Knapp wrote:
>
>> Let's say I have a numeric field and a button to increase the value and
>> a button to decrease the value. When I click the increase button,
On 18/02/2012 23:39, Marty Knapp wrote:
Let's say I have a numeric field and a button to increase the value and
a button to decrease the value. When I click the increase button, I want
it to increase to the next highest value that is evenly divisible by 20.
So if the field has a value of 19, a cl
Hi Marty,
Just create a repeat loop that increases or decreases the value by 1 until it
reaches a value where mod 20 of the value = 0; then exit the loop and your
value will be divisible by 20. I'll let you code this. This would be very fast
and quite simple.
Joe Wilkins
On Feb 18, 2012, at 3
Probably is an easier way but..
if your target number is an even 20, and the current value is 15
put 20 into targetNum
put 15 into curNum
(targetNum - (curNum mod targetNum)) + curNum --should do it.
On Sat, Feb 18, 2012 at 4:39 PM, Marty Knapp wrote:
> Let's say I have a numeric field and a b
11 matches
Mail list logo