我创建了一个jformattedtextfield来只接受数字:
NumberFormat f2 = NumberFormat.getNumberInstance();
txtformattedprice = new javax.swing.JFormattedTextField(f2);
现在我从我的数据库表中收到价格的价值,我想把它放在txtformattedprice中:
rsriga.next(); //the code above is ok
txtformattedprice.setText(Double.toString((rsriga.getDouble("Price"))));
在我的数据库中,专栏" Price"是十进制(6,2)(值的例子:14.15),如果我运行应用程序我在txtformattedprice中获取值:14.15但我想要14,15因为如果用户在txtformattedprice中单击然后他点击了在另一个文本字段中,14.15的值变为1.415(现在它不是小数)。 我怎么能在txtformattedprice 14,15?
答案 0 :(得分:1)
如果我理解了您的问题,您可以使用JFormattedTextField#setValue(Object)
,它应使用您传入的NumberFormat
来设置值。像,
// You may not need the cast, not sure if rsriga returns double or Double
txtformattedprice.setValue((Double) rsriga.getDouble("Price"));