
Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
On Aug 15, 2:43 am, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:
> >does some know what is the bonus 9.700000000001 value?
>
[quoted text clipped - 5 lines]
> Roedy Green Canadian Mind Products
> The Java Glossaryhttp://mindprod.com
Looking at his SSCCE, I've noticed the same behavior, but here's
exactly what I notice...
"Spinning" the value up or down will sometimes cause a non-exact
floating point number (11.29999999999999). The next click after that
will cause two values, first the rounded version, THEN the new current
version.
Very odd indeed.
Michael Jung - 15 Aug 2007 18:41 GMT
> On Aug 15, 2:43 am, Roedy Green <see_webs...@mindprod.com.invalid>
> wrote:
[quoted text clipped - 13 lines]
> will cause two values, first the rounded version, THEN the new current
> version.
Not having seen the implementation of SpinnerModel, I assume the following
happens. A new number is an increment of the old as (integer) multiples of
0.1. After this is calculated, a stateChange event is fired. The next step
is rounding the resulting number to a multiple of 0.1. If this is different
from the originally calculated number, another state change is fired. Note
that this can happen, since 0.1 is not a machine number and multiples must be
rounded.
Michael
Roedy Green - 16 Aug 2007 00:41 GMT
On Wed, 15 Aug 2007 15:20:14 -0000, Daniel Pitts
<googlegroupie@coloraura.com> wrote, quoted or indirectly quoted
someone who said :
>"Spinning" the value up or down will sometimes cause a non-exact
>floating point number (11.29999999999999). The next click after that
>will cause two values, first the rounded version, THEN the new current
>version.
He needs a DecimalFormat that will round the value to X decimal
places.
See the code for CanadianTax where I do that on a spinner to display
price.
see http://mindprod.com/applet/canadiantax.html

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
>>does some know what is the bonus 9.700000000001 value?
>
> one thing that drives you a bit nuts is when you set the value of a
> Component programmatically it will generate a change event. So you
> can get yourself in infinite regress if you are not careful, e.g. if
> you tidy the value on a change event.
This can be avoided. Make each event handler a separate instance of some
class implementing the appropriate interface. Put an ivar like this in:
private boolean inHandler = false;
and in the handler method,
if (inHandler) return;
inHandler = true;
try {
.
.
.
} finally {
inHandler = false;
}