gpt4 book ai didi

android - 如何避免双重科学记数法?

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:21:40 24 4
gpt4 key购买 nike

这是我的简单代码

        @Override
public void onClick(View v) {
try {
double price = Double.parseDouble(ePrice.getText().toString());
double percent = Double.parseDouble(ePercent.getText().toString());

double priceValue = price * percent/100.0f;
double percentValue = price - priceValue;

moneyToGet.setText(String.valueOf(priceValue));
moneyToPay.setText(String.valueOf(percentValue));

moneyToGet.setText("" + priceValue);
moneyToPay.setText("" + percentValue);

// catch
} catch (NumberFormatException ex) {
// write a message to users
moneyToGet.setText("");
}
}

});

这是一个简单的百分比计算器代码。

我想要的是避免在我的计算器中使用科学计数法,因为我不想向用户解释什么是科学计数法。

例如如果我想计算100,000,000并削减50%,它应该给我50,000,000> 这给了我 5.0E7 在我的例子中,这对用户没有任何意义。当然,我知道这两个结果都是正确的。提前致谢。

最佳答案

检查答案 here .你可以写

moneyToGet.setText(String.format("%.0f", priceValue));

关于android - 如何避免双重科学记数法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20813631/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com