I'd like to convert a BigDecimal
to String
for printing purposes but print out all digits without scientific notation. For example:
BigDecimal d = BigDecimal.valueOf(12334535345456700.12345634534534578901);
String out = d.toString(); // Or perform any formatting that needs to be done
System.out.println(out);
I'd like to get 12334535345456700.12345634534534578901
printed. Right now I get: 1.23345353454567E+16
.
You want to use a
DecimalFormat
:You could use this
To preserve the precision for a
BigDecimal
you need to pass the value in as aString
The
BigDecimal
class has atoPlainString
method. Call this method instead of the standardtoString
and it will print out the full number without scientific notation.Example