New Math

Mike Bonner bonnmike at gmail.com
Sat Feb 18 19:10:25 EST 2012


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 <ken at kencorey.com> 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, 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?
>>
>
> Geoff Canyon just published this in another thread:
> --------------------
> function roundUp x,i -- rounds x up to the next i
>   return ((x - .00001) div i + 1) * i
> end roundUp
>
> put roundUp(curValue,20) into field "blah"
> --------------------
>
> Seems elegant and very readable to me.
>
> -Ken
>
> ______________________________**_________________
> 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<http://lists.runrev.com/mailman/listinfo/use-livecode>
>



More information about the use-livecode mailing list