New Math

Alex Tweedly alex at tweedly.net
Sat Feb 18 19:30:38 EST 2012


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 19/02/2012 00:11, Jerry Jensen wrote:
> 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 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 click will set the value to 20. If the field has a value of 121, a click would increase  it to 140.
>>
>> I know I could do it by adding (or subtracting in the case of a decrease) but is there a more elegant and/or faster way to do that?
>>
>> Thanks,
>> Marty K
>>
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
> .
>





More information about the use-livecode mailing list