【问题标题】:convert a double scientific notation to decimal notation in JNI在 JNI 中将双科学记数法转换为十进制记数法
【发布时间】:2014-08-06 11:07:21
【问题描述】:
我的活动中有 jdouble(double) 值,在打印时以科学记数法给出,即 E 格式。现在我想以十进制格式显示它并截断它,所以我在格式说明符中使用了“%.2f”来做到这一点。但奇怪的是,“%f”格式说明符将 0.000000 显示为最终值。请提出一些建议。
P.S 我在 android 的本机端这样做。
【问题讨论】:
标签:
android
c
formatting
java-native-interface
double
【解决方案1】:
为了显示小数而不是 E 格式符号并截断数字,您可以使用 NumberFormat:
NumberFormat formatter = new DecimalFormat("#0.000");
然后,您想在哪里使用您的号码:
formatter.format(yournumber)
例如:
Toast.makeText(context, "Truncated number: " + formatter.format(yournumber), Toast.LENGTH_LONG).show();
在这种情况下,您的号码将显示为 3 位小数。
添加与要显示的小数一样多的零。