More sensible BigDecimal toString()?
The standard behaviour of BigDecimal.toString() makes no sense to me. In the JavaDoc you see
[123, -1] "1.23E+3"
Why would you ever want to show 1,230 as 1.23E+3?
Is there a simple way to convert a BigDecimal to a string such that scientific notation is used if the exponent is bigger/smaller than a certain value, like a pocket calculator does?
Re: More sensible BigDecimal toString()?
Your best bet for questions like these is to first check the API as it often will solve this problem a lot faster than we can. And in fact it does! Check out a method of BigDecimal that begins with toPlain...() in the BigDecimal API. You'll have to supply your own program logic to decide which method to call.
Re: More sensible BigDecimal toString()?
The API also describes the sense behind the current (>1.4) toString() behaviour. It may not be what you want in some context, but it is as sensible as it could be.
Re: More sensible BigDecimal toString()?
I'm puzzled why there is toPlainString and toEngineeringString but no toScientificString?
toString doesn't guarantee producing scientific notation, so there are some numbers where you don't have the option of scientific format. OK, probably not numbers which you would want in that format.
In practical terms, if I wanted scientific notation for numbers outside, say 10^8 and 10^-8, is toString always going to do that?
Whether the behaviour of toString is as sensible as it could be is a matter of opinion - they have designed to be reversible and locale independent, but at the expense of readability and general usefulness IMHO.