我想创建价格格式
我通过搜索在互联网上找到了这段代码
/*
/ other code
*/
// create price format
DecimalFormat formatData = new DecimalFormat("#.##");
/*
/ other code
*/
Menu_price.add(Double.valueOf(formatData.format(menu.getDouble("Price"))));或
Menu_price = Double.valueOf(formatData.format(menu.getDouble("Price")));
/*
/ other code
*/ 它可以工作,但如果我有一个像20这样的数字,它会给我这样的结果:
20.0
我想要的是:
20
有什么建议吗?
发布于 2016-05-22 23:34:57
在这种情况下,只需将DecimalFormat("#.##")更改为DecimalFormat("#");。
或使用
double prizeInDouble = menu.getDouble("Price");
Menu_prize = prizeInDouble.intValue();或者做
Menu_prize = (int) prizeInDouble;https://stackoverflow.com/questions/37376199
复制相似问题