Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Call BigDecimal.toPlainString() when a decimal string must not contain an exponent. It does not round the value; it writes the existing decimal according to the number’s scale.

BigDecimal amount = new BigDecimal("1.2300E+7");
String plain = amount.toPlainString(); // "12300000"

Constructing the value from a decimal string specifies the intended decimal directly, without first converting through binary floating-point.

Why BigDecimal.toString() may use scientific notation

BigDecimal represents a decimal with an unscaled integer and a scale. For a nonnegative scale, the scale gives the number of digits to the right of the decimal point. A negative scale means the unscaled value is multiplied by a power of ten.

toString() returns BigDecimal’s canonical string representation, which can use an exponent. The Java API’s notation rule uses the adjusted exponent, calculated as -scale + (precision - 1), where precision is the number of decimal digits in the absolute unscaled value. When the scale is nonnegative and the adjusted exponent is at least -6, the plain form is used; otherwise, scientific notation is used. This rule is specific to BigDecimal’s API contract, not a general rule for every Java number type. Oracle Java SE 11 BigDecimal API

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How to use toPlainString()

toPlainString() guarantees a representation without an exponent field. The decimal point and integer zeros are placed according to the value’s scale; the method does not choose a new precision or rounding policy. Oracle Java SE 24 BigDecimal API

For positive scale, the output has the requested number of digits after the decimal point, including trailing zeros represented by the scale. For zero or negative scale, the output is an integer form; a negative scale adds the corresponding zeros. Oracle Java SE 19 BigDecimal API

What happens to trailing zeros and scale

Plain-string conversion is not the same as formatting to a fixed number of decimal places. A value with a scale that includes trailing fractional zeros can show those zeros in the output. If the result must have a particular number of decimal places, set the desired scale and rounding policy explicitly before converting it.

Parsing the plain result back into a BigDecimal preserves its numerical value, but not necessarily the original scale and unscaled-value pair. In particular, when the source has negative scale, parsing its plain integer string creates a value with scale zero.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When to choose another method

  • toPlainString(): use when exponent notation is not allowed.
  • toString(): use for BigDecimal’s canonical representation, which may use scientific notation according to its API rule.
  • toEngineeringString(): use when exponent notation is acceptable but engineering exponents are preferred. Its exponent is adjusted to a multiple of three, with a nonzero integer part from 1 through 999.
  • NumberFormat and its subclasses: use for locale-sensitive formatting or parsing. Oracle Java SE 11 BigDecimal API
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Watch for very large output

A plain representation can be enormous when a BigDecimal has an extreme scale. Oracle’s Java SE 24 API notes that new BigDecimal(1E-1000000000) can produce a toPlainString() result longer than one billion characters. If a scale or decimal input is uncontrolled, validate it and place sensible limits on output size before creating the string. Oracle Java SE 24 BigDecimal API

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.