Search code examples
javaswingnumber-formattingjformattedtextfieldnumberformatter

JFormattedTextField removes fraction part


Whenever I enter any number with a fraction for example 50.25 the fraction part gets removed to 50.00.

DecimalFormat decimalFormat = new DecimalFormat("#,##0.00");
NumberFormatter currencyFormatter = new NumberFormatter(decimalFormat);
currencyFormatter.setMinimum(0);

JFormattedTextField AmountField = new JFormattedTextField(currencyFormatter);

How can I fix it to accept fraction numbers?


Solution

  • Changing setMinimum value solved the problem:

    currencyFormatter.setMinimum(0.00);