如何避免科学记数法的双? [英] How to Avoid Scientific Notation in Double?

查看:139
本文介绍了如何避免科学记数法的双?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我简单的code

Here is my simple code

        @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("");
        }
    }

});

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

This is a simple code for Percentage Calculator.

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

What I want is to avoid the Scientific Notation in my Calculator cause I don't want to explain to user what is Scientific Notation.

例如如果我要计算它的亿 50%,应该给我的 50000000 这是给我的 5.0E7 ,然后在我的情况是不作任何场景的用户。当然,我知道,这两个结果是正确的。 在此先感谢。

For example if I want to calculate 100,000,000 and cut 50% of it, it Should give me 50,000,000 which is giving me 5.0E7 And in my case is doesn't make any scene for user. And of course I know both results are correct. Thanks in Advance.

推荐答案

检查答案<一href="http://stackoverflow.com/questions/16098046/how-to-print-double-value-without-scientific-notation-using-java">here.你可以写

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

这篇关于如何避免科学记数法的双?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆