我有下面的代码:
System.out.println(transaction.getAmount());
以这种形式返回金额:100.0
(即double
)。
如何将其转换为以下形式:10000
?
最佳答案
乘以 100 并得到整数值:
System.out.println(Double.valueOf(transaction.getAmount() * 100).intValue());
另一种选择是使用String.format()
double amount = transaction.getAmount();
System.out.println(String.format("%1$,.2f", amount).replace(".", ""));
关于java - 将 Double 转换为特定形式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27063688/