title: JFormattedTextField and NumberFormat to work with Float
body: <p>I made a small dialog with a JFormattedTextField, to enter a Float number between 0 and 10 up to 3 decimal numbers. I'm using NumberFormat for that, and a PropertyChangeListener to validate the value or get back to the old value. But it is not working:</p>
  
  <pre><code>public class IRCompensationDialog extends JDialog{
  
  private static final long serialVersionUID = 1L;
  
  private JDialog irDialog;
  private JButton cancelButton, okButton;
  private JFormattedTextField resistorValue;
  private INode nodo;
  
  public IRCompensationDialog(int idNodo) throws BusinessException, ParseException{
      super(MainFrame.getInstance());
      this.irDialog = this;
      this.setResizable(false);
      this.setModal(true);
      this.setTitle("IR Compensation");
      this.nodo = new ServicesFactoryImpl().getNodesServices().getNode(idNodo);
  
      initComponents();
  
      this.pack();
      this.setLocationRelativeTo(null);
      this.setVisible(true);
  }
  
  private void initComponents() throws ParseException{
      NumberFormat numberFormat = NumberFormat.getInstance();
      numberFormat.setMaximumFractionDigits(3);
      resistorValue = new JFormattedTextField(numberFormat);
      resistorValue.addPropertyChangeListener("value", new IRValueChangeListener());
      float currentValue = nodo.getIR() / 1000;
      resistorValue.setValue(currentValue);
  
      JPanel botonera = new JPanel();
      cancelButton = new JButton("Cancel");
      cancelButton.addActionListener(new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
              irDialog.setVisible(false);
          }
      });
      botonera.add(cancelButton);
      okButton = new JButton("OK");
      okButton.addActionListener(new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
              Float newValue = (Float)resistorValue.getValue()*1000;
              nodo.setIR(newValue.intValue());
          }
      });
      botonera.add(okButton);
  
      this.setLayout (new BorderLayout());
      this.add (resistorValue, BorderLayout.CENTER);
      this.add (new JLabel("Enter resistor value (Ohms):"), BorderLayout.NORTH);
      this.add (botonera, BorderLayout.SOUTH);
  }
  
  private class IRValueChangeListener implements PropertyChangeListener{
  
      @Override
      public void propertyChange(PropertyChangeEvent evt) {
          JFormattedTextField field = (JFormattedTextField) evt.getSource();
          Float newValue = (Float)evt.getNewValue().toString();
  
          if(newValue&gt;0 &amp;&amp; newValue&lt;=10000){
              JOptionPane.showMessageDialog(MainFrame.getInstance(), " Value must be between 0 and 10 Ohm", "Error", JOptionPane.ERROR_MESSAGE);
              Float oldValue = (Float) evt.getOldValue();
              field.setValue(oldValue);
          }
  
      }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>INode is a class I made, which stores an <strong>int</strong> value I'm getting with getIR() method and updating it with setIR(int) method.</p>
  
  <p>I'm getting java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Float in the line <code>Float newValue = (Float)resistorValue.getValue()*1000;</code> and also at line <code>Float newValue = (Float)evt.getNewValue();</code></p>