【发布时间】:2014-05-03 02:09:22
【问题描述】:
我只想显示数字的尾数,而与指数无关。
12.4e-6 after formatting => 12.4
12.4e-12 after formatting => 12.4
手动进行计算很简单。但问题是我需要使用 DeciamalFormat 类,因为我必须将它作为参数提供给另一个类。我试过这个:
DecimalFormat mFormat = (DecimalFormat) NumberFormat.getInstance();
mFormat.applyPattern("#.#E0");
如果我删除 E 符号,尾数将不会被计算。有没有办法使用这个DecimalFormat 只显示mantissa?
【问题讨论】:
-
124e-7=12.4e-6=1.24e-5=0.124e-4所以你想打印一个 124 = 0.124 的数字? -
或者你只是想乘以 1e6?例如12.4e-6 => 12.4 但 1.24e-6 => 1.24 和 1.24e-3 => 1240
-
12.4e-6=12400000e-12你想要哪个号码? -
我不想乘以 1e6 等特定因子。我想有两个整数数字,然后是两个小数数字并忽略指数。 12.4e-12 => 12.4(输出是格式化后的字符串)1233e-12 => 12133 0.12e-5 => 0.12 所以只是尾数。
-
我的观点是,您声明的要求毫无意义,因为 1233e-12 与 1.233e-6 的数字相同,所以根据您的要求,它应该打印什么?同一个数字不能有多个可能的输出。
标签: java android number-formatting decimalformat mantissa