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
精彩评论