开发者

asterisk in arithmetic output

When computing 2 doubles, 1/81 on the android platform, 0.01234567* was returned. What does the asterisk mean and how can I avoid such an output?

a=Double.parseDouble(subexp.substring(ss, i));
b=Double.parseDouble(subexp.substring(i+1, se+1));

subexp=subexp.substring(0,ss).concat(Double.toString(a/b))
.concat(subexp.substring(se+1,subexp.length()));

so basically the piece of offen开发者_开发知识库ding code is above, with the following values grabbed from the debugger:

subexp="1+1/81" (before code)
"1+0.01234567*" (after code) 

ss=2, se=5, i=3, a=1.0, b=81.0


Not to be a smartass, but if you just don't want the asterisk, try this immediately before you output your string:

subexp = subexp.replaceAll("\\*", "");

If your result requires something more elaborate than this, please provide more information and/or more complete source code, and I'll try to adapt my answer.

I made a simple project to test your code as posted. I printed the string out in the console as well as putting it in a TextView. In both places I get "1+0.012345689012345678", so I can't seem to replicate your results with the asterisk. Perhaps the problem is somewhere else in your code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜