tags:

views:

64

answers:

3

Hi all

I had a jFormattedTextField with Name Hectare. the value is declared as double as shown below

         String cultivationSize = jFormattedTextField3.getText();
         double hectare = Double.parseDouble(cultivationSize);

now the problem is when i enter more than 3 digits the by default comma is entered after 3digits as 1,000. i hav to add the value to other value. due to thz comma im unable to do it.

how can i remove comma add these values

A: 

use string.replace(",","");

i.e. your code should look like -

double hectare = Double.parseDouble(cultivationSize.replaceAll(",",""));
Gopi
+6  A: 

Call the getValue() instead of getText() on JFormattedTextField

naikus
+1  A: 

You should use MaskFormater like this:

zipField = new JFormattedTextField(
                    createFormatter("#####"));
...
protected MaskFormatter createFormatter(String s) {
    MaskFormatter formatter = null;
    try {
        formatter = new MaskFormatter(s);
    } catch (java.text.ParseException exc) {
        System.err.println("formatter is bad: " + exc.getMessage());
        System.exit(-1);
    }
    return formatter;
}
jitm