Am 21.09.2015 um 13:24 schrieb Riccardo Mottola <[email protected]>:

> 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.

You could try to attach an action method and each time the stepper changes, 
round the position up/down to the precision you expect.
This should avoid to accumulate rounding errors (float/double are not infinite 
precision).

Something like

[stepper setDoubleValue:rint([stepper doubleValue]*10.0)/10.0];

Use 100.0 if you have 0.01 steps etc. So basically the factors should be the 
step size.

BR,
Nikolaus

> 
> Thanks - Riccardo
> 
> 
> 
> _______________________________________________
> Discuss-gnustep mailing list
> [email protected]
> https://lists.gnu.org/mailman/listinfo/discuss-gnustep


_______________________________________________
Discuss-gnustep mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/discuss-gnustep

Reply via email to