双转换为字符串转换为、字符串

由网友(别碰我心)分享简介:我不知道是我还是什么,但我有一个问题,将double转换字符串。I am not sure it is me or what but I am having a problem converting a double to string.这是我的code:double total = 44;String tot...

我不知道是我还是什么,但我有一个问题,将double转换字符串。

I am not sure it is me or what but I am having a problem converting a double to string.

这是我的code:

double total = 44;
String total2 = Double.toString(total);

我是做错了还是我缺少一个步骤在这里。

Am i doing something wrong or am i missing a step here.

我得到错误 NumberFormatException异常尝试转换这个当。

I get error NumberFormatException when trying to convert this.

totalCost.setOnTouchListener(new OnTouchListener() {
  public boolean onTouch(View v, MotionEvent event) {
    try {
      double priceG = Double.parseDouble(priceGal.getText().toString());
      double valG = Double.parseDouble(volGal.toString());
      double total = priceG * valG;
      String tot = new Double(total).toString();
      totalCost.setText(tot);
    } catch(Exception e) {
      Log.e("text", e.toString());
    }

    return false;
  }         
});

我试图做到这一点在onTouchListener。生病后更code,基本上当用户触摸我想要的信息计算填土的EditText框的EditText框。

I am trying to do this in an onTouchListener. Ill post more code, basically when the user touches the edittext box i want the information to calculate a fill the edittext box.

推荐答案

双总= 44; 串共2 =将String.valueOf(总);

double total = 44; String total2 = String.valueOf(total);

这将double转换为String

This will convert double to String

阅读全文

相关推荐

最新文章