开发者

Java Bigdecimal Range Issue

For below java Code it dispaly 0E-10 as output

 BigDecimal bd = new BigDecimal("00.0000000000");
 System.out.println(bd); // output is 0E-10

0E-10 is due to range value of Bigdecimal. but is there any way i can display as like input 00.0000000000开发者_如何学Python without much coding.?


BigDecimal#toPlainString() will give the decimal part . Note it doesnt exactly satisfy your requirements

If you the op formatted , use DecimalFormat


BigDecimal bd = new BigDecimal("00.0000000000");
System.out.println(bd.toPlainString()); // output = 0.0000000000

As stated by amal you can simply use BigDecimal.toPlainString():

public String toPlainString()
   Returns a string representation of this BigDecimal without an exponent field
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜