[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: NSStepper Action Problem
From: |
David Chisnall |
Subject: |
Re: NSStepper Action Problem |
Date: |
Mon, 21 Sep 2015 12:35:32 +0100 |
The simplest fix may be to modify the stepper to use a double for the value.
Given that steppers are commonly used with fixed increments that make sense in
base 10, a better solution might be to modify it to store a base value and a
number of applications of the increment, so that in your case it would be
stored as 1000 + 0.1 * 100000… (i.e. base + step*steps), with the calculation
performed on update. If the user enters a new value without using the stepper
buttons, then set this to the new base.
David
> On 21 Sep 2015, at 12:24, Riccardo Mottola <riccardo.mottola@libero.it> wrote:
>
> Hi,
>
> I noticed that when I define a NSStepper with a wide range (e.g. 1000) and a
> float increment of 0.1, after a dozen of "increments" things go adrift with a
> rounding error.. eg 5.10000001 instead of 5.1
>
> I have tested on Mac 10.5 and PPC and get different errors (e.g. 5.099999998)
> but the problem is the same, it is nto a GS bug, but probably a problem on
> how the internals are handled.
>
> What solution is possible? I have both a textfield and a stepper that should
> interact.
> I was thinking of just getting the "action" of the Stepper and then keeping a
> variable of mine with, eventually a different precision or that does other
> rounding tricks.
> However, how can I know if increment or decrement have been clicked? Is there
> a trick? can I reliably put an action on the two arrows but action was
> desired by the user?
>
> A really crude workaround would be to use just a very high number in the
> stepper, integer values and not-wrapping and thus compating old and new value
> to know if "+" or "-" were the choice, but looks pretty much a hack.
>
> Thanks - Riccardo
>
>
>
> _______________________________________________
> Discuss-gnustep mailing list
> Discuss-gnustep@gnu.org
> https://lists.gnu.org/mailman/listinfo/discuss-gnustep
-- Sent from my IBM 1620