在我看来,我有以下代码
IndexedContainer icLoaded = new IndexedContainer();
icLoaded.removeAllItems();
icLoaded.removeAllContainerFilters();
icLoaded.addContainerProperty("Average Cost", Double.class, null);
Run Code Online (Sandbox Code Playgroud)
在模型中我有以下代码
public IndexedContainer DoFetchstockCodesTable(String passedSQL,
IndexedContainer passTable, String CustomsaleQuerry) {
try {
Class.forName(dbsettings.dbDriver);
final Connection conn = DriverManager.getConnection(
new Home().GiveMeSessionDB(), dbsettings.dbUsername,
dbsettings.dbPassword);
final Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(passedSQL.trim());
while (rs.next()) {
passTable.addItem(rs.getString("item_id"));
passTable.getContainerProperty(rs.getString("item_id"),
"Average Cost").setValue(rs.getDouble("average_cost"));
Run Code Online (Sandbox Code Playgroud)
我怎么能转换下面
passTable.getContainerProperty(rs.getString("item_id"),
"Average Cost").setValue(rs.getDouble("average_cost"));
Run Code Online (Sandbox Code Playgroud)
显示一个带有2个小数位的数字,用逗号分隔符分隔,如1,000.12使用
NumberFormat numberFormat = new DecimalFormat("#,###.00");
Run Code Online (Sandbox Code Playgroud)
当我使用下面的内容时,不显示任何内容.
passTable.getContainerProperty(rs.getString("item_id"),
"Average Cost").setValue(numberFormat.format(rs.getDouble("average_cost")));
Run Code Online (Sandbox Code Playgroud)
您调用NumberFormat#format(double)并保存格式double为a String,因为a double是原始值,并且没有固有的格式 -
NumberFormat numberFormat = new DecimalFormat("#,###.00");
double val = 1000.12;
System.out.println(numberFormat.format(val));
Run Code Online (Sandbox Code Playgroud)
输出是
1,000.12
Run Code Online (Sandbox Code Playgroud)
编辑
你需要改变它
icLoaded.addContainerProperty("Average Cost", Double.class, null);
Run Code Online (Sandbox Code Playgroud)
至
icLoaded.addContainerProperty("Average Cost", String.class, null);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2775 次 |
| 最近记录: |