How to remove comma from TextField in Java
I have a JFormattedTextField named Hectare. A double type value is declared as shown below.
String cultivationSize = JFormattedTextField3.getText();
double hectare = Double.parseDouble(cultivationSize);
Now the problem is that when you enter more than three digits, by default the comma is entered after the three digits, for example. 1000. I have to add this value to some other value. But because of this comma, I cannot do it.
How do I remove the comma and add that value to another value?
+2
source to share
4 answers
You must 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;
}
+1
source to share