I need to set a float value of a JSpinner with 2 decimals, but I always have this error:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: illegal value
at java.desktop/javax.swing.SpinnerNumberModel.setValue(SpinnerNumberModel.java:456)
at java.desktop/javax.swing.JSpinner.setValue(JSpinner.java:355)
all Spinners has this model --> SpinnerNumberModel(0.01, 0.01, 10000.00, 0.01);
float a = Float.parseFloat(aSpinner.getValue().toString());
float b = Float.parseFloat(bSpinner.getValue().toString());
float c = b / 100 * 95;
DecimalFormat decimalformat = new DecimalFormat("#.##");
cSpinner.setValue(decimalformat.format(c));
What am I doing wrong?
I tried to give it a float value and it doesn't work, I tried to give it a String value and it doesn't work.
Can someone help me, please?
NumberFormat.format(double)returns aString, where assetValuewhen the spinner has aSpinnerNumberModelwill be expecting a numeric value (e.g.floatordouble).On a wider note, number formats are only intended to be used for output on a GUI (the view) or printing to the console or a file, etc. Internally (in the model etc) the value should be numeric.