how to add only double values in jformattedtextfield

3.2k views Asked by At

I need to format jformattedtextfeild for only add double/float values with two decimal places in runtime.
ex: 15600.00
Please help me on this. Thank you.

1

There are 1 answers

0
oizulain On

Here's an example on how to do it:

NumberFormat format = DecimalFormat.getInstance();
format.setMinimumFractionDigits(2);
format.setMaximumFractionDigits(2);
format.setRoundingMode(RoundingMode.HALF_UP);
JFormattedTextField myTwoDecimalTextfield = new JFormattedTextField(format);
myTwoDecimalTextfield.setValue(new Float(3.14));