3

首先请原谅我英语不好。

我是 Android 开发的新手。我有一个问题,认为你可以解决它。

问题是:

我有一个非常大的 double 值,就像12345678987654321在我的 android 应用程序中一样,但是当我想显示它时EditText,它会像这样显示12345678987654300。在这种情况下,当我的值字符超过15 个字符时, android 显示剩余的字符为“0”

我不知道我必须做什么。

我正在使用此代码:

DecimalFormat df = new DecimalFormat("#.#########");
double a = Distancevals[1] * Distancevals[2];
//Distancevals is an array of double with big values
EditText editto = (EditText)findViewById(...);
editto.setText(df.format(a));
4

4 回答 4

1

Double12345678987654321以格式存储您的号码1.23456789876543E16,因此您丢失了号码的结尾21。当您格式化结果时,就知道您的数字由 17 个符号组成,因此format函数在您的数字末尾添加两个零,而不是21.

尝试使用这个:

DecimalFormat df = new DecimalFormat("#.#########");
BigDecimal a = new BigDecimal(Distancevals[1] * Distancevals[2]);
// Distancevals is an array of double with big values
EditText editto = (EditText) findViewById(...);
editto.setText(df.format(a));
于 2011-12-29T12:38:10.067 回答
0

试试这个

DecimalFormat df= new DecimalFormat("###############00");
double a=Distancevals[1]*Distancevals[2];
//Distancevals is an array of double with big values
EditText editto=(EditText)findViewById(...);
editto.setText(df.format(a));
于 2011-12-29T11:33:36.470 回答
0

您只需将其显示为editto.setText(a+"");

因为在你的情况下 EditText 没有做任何事情,但 DecimalFormat 正在改变你的号码。

于 2011-12-29T12:34:31.887 回答
0

我建议在这一行:

editto.setText(df.format(a));

将其更改为:

editto.setText(df.format(a.toString()));
于 2016-11-05T05:29:32.103 回答