科学记数法错误 [英] Scientific notation error

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

问题描述

我通过intelli j idea制作了一个简单的基于公式的计算器。它与小数字完美配合,但当我输入大数字时,它显示5.0E454作为答案。如何删除此错误以便我得到完美的数字答案?



我尝试过:



 public void end(View v){
EditText princi1;
EditText annu1;
EditText time1;
EditText interest1;
EditText comp1;
TextView ans1;
princi1 =(EditText)findViewById(R.id.principal);
annu1 =(EditText)findViewById(R.id.annual);
interest1 =(EditText)findViewById(R.id.rate);
comp1 =(EditText)findViewById(R.id.compund);
ans1 =(TextView)findViewById(R.id.answer);
time1 =(EditText)findViewById(R.id.years);

double p = Double.parseDouble(princi1.getText()。toString());
double an = Double.parseDouble(annu1.getText()。toString());
double r = Double.parseDouble(interest1.getText()。toString());
int co = Integer.parseInt(comp1.getText()。toString());

int t = Integer.parseInt(time1.getText()。toString());
double r2 = r / 100;

for(int i = 1; i< = t; i ++){
p =(p * Math.pow(1 + r2 / co,co))+ an;
}
ans1.setText(Double.toString(p));
}

解决方案

可能是因为像5.0E454这样的数字是一个非常大的数字!

想想它 - 如果你显示5.0E454作为一个整数,然后它是一个5后跟454个零:

<预LANG =文本> 50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

您将需要一个非常大的手机显示这样的数字!



引用:

我刚才给了一个例子。

现在在我的程序中如果我拿p = 10,000,000

an = 1000

r = 10

co = 1

t = 10

而不是显示19,497,606.888

显示1.949760688810001E7

所以给我们一些实际相关的例子!



有几种方法可以控制输出:

 import java.text。*; 
公共类Main
{
public static void main(String [] args){
double d = 19497606.888;
System.out.println(Double.toString(d));
System.out.println(String.format(%f,d));
DecimalFormat decimalFormat = new DecimalFormat(#0);
System.out.println(decimalFormat.format(d));
}
}

会给你:

 1.9497606888E7 
19497606.888000
19497607


I have made a simple formula based calculator through intelli j idea. it works perfectly with small numbers,but when i input large numbers it shows 5.0E454 as answer.How can i remove this error so that i get perfect numerical answer?

What I have tried:

public void end(View v){
        EditText princi1;
        EditText annu1;
        EditText time1;
        EditText interest1;
        EditText comp1;
        TextView ans1;
        princi1=(EditText)findViewById(R.id.principal);
        annu1=(EditText)findViewById(R.id.annual);
        interest1=(EditText)findViewById(R.id.rate);
        comp1=(EditText)findViewById(R.id.compund);
        ans1=(TextView) findViewById(R.id.answer);
        time1=(EditText)findViewById(R.id.years);

        double p=Double.parseDouble(princi1.getText().toString());
        double an=Double.parseDouble(annu1.getText().toString());
        double r=Double.parseDouble(interest1.getText().toString());
        int co =Integer.parseInt(comp1.getText().toString());

        int t=Integer.parseInt(time1.getText().toString());
        double r2=r/100;

        for (int i = 1; i <= t; i++){
            p = (p * Math.pow(1 + r2 / co, co))+an;
        }
        ans1.setText(Double.toString(p));
    }

解决方案

Probably because numbers like 5.0E454 is a very big number!
Think about it - if you display 5.0E454 as an integer then it's a 5 followed by 454 zeros:

50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

You are going to need a very large phone to show numbers like that!

Quote:

i just gave an example.
now in my program if i take p=10,000,000
an=1000
r=10
co=1
t=10
instead of showing 19,497,606.888
it shows 1.949760688810001E7

So give us examples that are actually relevant!

There are several ways to control the output:

import java.text.*;
public class Main
{
	public static void main(String[] args) {
	    double d = 19497606.888;
		System.out.println(Double.toString(d));
		System.out.println(String.format("%f", d));
        DecimalFormat decimalFormat = new DecimalFormat("#0");
		System.out.println(decimalFormat.format(d));
	}
}

Will give you:

1.9497606888E7                                                                             
19497606.888000                                                                            
19497607 


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

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