如何將double
格式化爲2個小數點? Decimalformat
或string.format
沒有給出預期輸出:Android雙精度十進制格式
DecimalFormat precision = new DecimalFormat("0.00");
s = mylist.get(0).getHARUALTAESGE();
double hramount = Double.parseDouble(s);
String rb = rebatespin.getSelectedItem().toString();
//below one
double rebamount = (Double.parseDouble(s) * Double.parseDouble(rb.replace("%", "")));
rebateamount.setText(precision.format(rebamount));
double hualr=(hramount-rebamount);
//below other one
haulageprice.setText(String.format("%.2f", hualr));
你看到什麼?輸出 –
我看到超過兩位小數 – neutr0n
請稍後在幾秒後顯示更多代碼 –