Please help me to set output of BigDecimal. For example: I need to output numbers which have a length that is less than 8 digits like this: "12345678", and if more then: "1,2345Е+9".
Methods
toPlainString();
toEngineeringString();
toString();
are not working as expected:
public class TestBigDecimalOutput {
public static void main(String[] args) {
BigDecimal d = new BigDecimal("57657657657453646587980887663654676580.24545346565476767645");
String outPlainString = d.toPlainString();
String outEngineeringString = d.toEngineeringString();
String outString = d.toString();
System.out.println(outPlainString);
System.out.println(outEngineeringString);
System.out.println(outString);
}
}
The code above produces the following output:
57657657657453646587980887663654676580.24545346565476767645
57657657657453646587980887663654676580.24545346565476767645
57657657657453646587980887663654676580.24545346565476767645
Give me a hint what am I doing wrong?