how to add only double values in jformattedtextfield

99封情书 提交于 2019-12-11 02:47:51

问题


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:


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));


来源:https://stackoverflow.com/questions/27056539/how-to-add-only-double-values-in-jformattedtextfield

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!