ero*_*ppa 2 java formatting numbers
如何在Java中将字符串0E-11转换为0.00000000000?我想以非科学记数法显示数字.我已经尝试过查看Java中的数字格式化程序,但是我需要具体说明我想要的确切小数位数,但我不会总是知道.我只想要原始数字所指定的小数位数.
显然,正确的答案是用户BigDecimal并检索精度和比例数.然后在Formatter中使用这些数字.像这样的东西:
BigDecimal bg = new BigDecimal(rs.getString(i));
Formatter fmt = new Formatter();
fmt.format("%." + bg.scale() + "f", bg);
buf.append( fmt);
Run Code Online (Sandbox Code Playgroud)
使用BigDecimal:
public static String removeScientificNotation(String value)
{
return new BigDecimal(value).toPlainString();
}
public static void main(String[] arguments) throws Exception
{
System.out.println(removeScientificNotation("3.0103E-7"));
}
Run Code Online (Sandbox Code Playgroud)
印刷品:
0.00000030103
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11185 次 |
| 最近记录: |