SpinnerNumberModel incorrect decimal values appearing
Hi,
I have created a custom JSpinner using a SpinnerNumberModel which holds values as Doubles but when I use the up and down arrows at some point the double value that is returned looses it's decimal precision. I created the following class:
public class DecimalSpinner extends JSpinner{
public DecimalSpinner( int displayDecimalPlaces, double value, double min, double max, double stepSize ) throws IllegalArgumentException {
SpinnerNumberModel model = new SpinnerNumberModel(value, min, max, stepSize);
this.setModel(model);
JSpinner.NumberEditor editor = (JSpinner.NumberEditor)this.getEditor();
DecimalFormat format = editor.getFormat();
format.setMinimumFractionDigits(displayDecimalPlaces);
}
}
And instantiate the class to have 6 decimal place precision as:
private DecimalSpinner m_spnTransferMin = new DecimalSpinner( 6, 0.1, 0.000001, 1000, 0.1);
when this is used 0.1 is displayed to begin with and pressing the up arrow gives the model values 0.1, 0.2, 0.30000000000000004. Where did this lack of precision come from as the value should be 0.3? Is this related to the fact that Doubles are only ever approximations? regardless how do I correct for this?

