开发者

Java Bigdecimal Range Issue

开发者 https://www.devze.com 2023-03-31 11:21 出处:网络
For below java Code it dispaly 0E-10 as output BigDecimal bd = new BigDecimal(\"00.0000000000\"); System.out.println(bd); // output is 0E-10

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

精彩评论

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