java单双数,Java以指数格式输出双数

I have some double numbers that are outputted with this format:

Format.String("%1.4e",doubleNumber);

The result is 1.123456e+03. How can I set the number of cipher of exponent for getting this format:

1.123456e+003

I would have always 3 cipher after e symbol.

Thank you

UPDATE 1:

I have partially resolved:

DecimalFormat formatter = new DecimalFormat("0.000000E000");

System.out.println( formatter.format(doubleNumber) );

Now the number has always the format

1.123456e0xx

or

1.123456e-0xx

But it's not all resolved. I would have always printed the sign:

1.123456e+0xx or 1.123456e-0xx

解决方案

Thank you @TDG

private String formatter(double number){

DecimalFormat formatter = new DecimalFormat("0.000000E000");

String fnumber = formatter.format(number);

if (!fnumber.contains("E-")) { //don't blast a negative sign

fnumber = fnumber.replace("E", "E+");

}

return fnumber;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值