执行计算后更改双精度数的显示格式
我使用双精度数执行计算,如下所示:
int minutes;
double seconds;
double DecMinutes;
// Handle Dd in; DMS, and DMm out
Calculate myCalculate = new Calculate(inDecimal); {
double outMinutes = myCalculate.getMinute();
double outSeconds = myCalculate.getSecond();
double outDecMinute = myCalculate.getDecMinute();
minutes = (int) outMinutes;
seconds = outSeconds;
DecMinutes = outDecMinute;
} // end myCalculate
// Convert result back to String
c = Integer.toString(minutes);
((EditText)findViewById(R.id.txtDMSLatMin)).setText(c);
((EditText)findViewById(R.id.txtDMmLatMin)).setText(c);
c = Double.toString(seconds);
((EditText)findViewById(R.id.txtDMSLatSec)).setText(c);
c = Double.toString(DecMinutes);
((EditText)findViewById(R.id.txtDMmLatDecMin)).setText(c);
我主要关心的是双精度 DecMinutes 输出。因为它是十进制分钟计算,所以我需要使用双精度。我的布局已将小数点显示为固定字符,因此我想在 EditText 框 txtDMmLatDecMin 中显示 0734,而不是显示 0.0734。
谢谢!!
I perform calculations using a double as follows:
int minutes;
double seconds;
double DecMinutes;
// Handle Dd in; DMS, and DMm out
Calculate myCalculate = new Calculate(inDecimal); {
double outMinutes = myCalculate.getMinute();
double outSeconds = myCalculate.getSecond();
double outDecMinute = myCalculate.getDecMinute();
minutes = (int) outMinutes;
seconds = outSeconds;
DecMinutes = outDecMinute;
} // end myCalculate
// Convert result back to String
c = Integer.toString(minutes);
((EditText)findViewById(R.id.txtDMSLatMin)).setText(c);
((EditText)findViewById(R.id.txtDMmLatMin)).setText(c);
c = Double.toString(seconds);
((EditText)findViewById(R.id.txtDMSLatSec)).setText(c);
c = Double.toString(DecMinutes);
((EditText)findViewById(R.id.txtDMmLatDecMin)).setText(c);
My main concern is with the double DecMinutes output. Because it's a Decimal-Minutes calculation I need to use double. My layout already displays the decimal point as a fixed character so instead of displaying 0.0734 I want to display 0734 in the EditText box txtDMmLatDecMin.
Thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本上,您想删除零和小数点吗?
也许有一种更简单的方法,但在我的脑海中,我想你可以使用
String.split()
。缺点是您必须创建一个新的字符串数组来保存值。所以在你这样做之后:
然后你可以这样做:
再说一次,也许有一个更简单的方法。 :)
So basically, you want to drop the zero and the decimal point?
Maybe there is an easier way, but at the top of my head I am thinking you can use
String.split()
. With the downside that you have to create a new String array to hold the values.So after you do this:
Then you can do:
Again, maybe there is an easier way. :)