【问题标题】:Android Studio using , insted of . after formatting stringAndroid Studio 使用 , 而不是 .格式化字符串后
【发布时间】:2017-06-07 13:37:43
【问题描述】:

我正在尝试制作一个计算器,但是在我格式化文本后,我得到了 XX 中的输出,XX 插入了 XX.XX,这会导致程序在重用数字时崩溃。

我的代码是:

                tempX = Double.parseDouble(xText.getText().toString());
                //tempY = Double.parseDouble(yText.getText().toString());
                tempA = Double.parseDouble(aText.getText().toString());
                tempB = Double.parseDouble(bText.getText().toString());


                tempY = tempA * tempX + tempB;
                yText.setText(String.format("%.2f", tempY));

【问题讨论】:

    标签: java android formatting


    【解决方案1】:

    随便用

    String.format(Locale.US, "%.2f", tempY);
    

    【讨论】:

      猜你喜欢
      • 2020-06-25
      • 2018-10-03
      • 1970-01-01
      • 2012-06-22
      • 2012-05-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多