[英]How to Show only two Digits after Decimal
我想在十進制后只顯示兩位數 ,我已經嘗試但仍然在十進制后得到多位數 :
itemamount = Double.parseDouble(text_cost_code.getText().toString());
txt_total.setText(new DecimalFormat("##.##").format(itemamount));
edit_qty_code.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
if (!edit_qty_code.getText().toString().equals("")
|| !edit_qty_code.getText().toString().equals("")) {
itemquantity = Double.parseDouble(edit_qty_code.getText().toString());
itemamount = Double.parseDouble(text_cost_code.getText().toString());
txt_total.setText(new DecimalFormat("##.##").format (itemquantity * itemamount));
} else { txt_total.setText("0.00");}}
我不確定你的代碼中你想要做什么,但是
String.format("%.2f", value);
應該管用。
Rakesh使用此鏈接:
i=348842.
double i2=i/60000;
DecimalFormat dtime = new DecimalFormat("#.##");
i2= Double.valueOf(dtime.format(time));
v.setText(String.valueOf(i2));
試試這個,它可能對你有幫助。
float localresult =Float.parseFloat(itemquantity*itemamount);
BigDecimal bd = new BigDecimal(Double.toString(localresult));
bd = bd.setScale(2,BigDecimal.ROUND_HALF_UP);
bd.doubleValue();
然后將其設置為textview,textview.setText(“”+ bd.doubleValue();)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.