Why does DecimalFormat ".#" and "0.#" have different results on 23.0?

Viewed 587

Why does java.text.DecimalFormat evaluate the following results:

new DecimalFormat("0.#").format(23.0)        // result: "23"

new DecimalFormat(".#").format(23.0)         // result: "23.0"

I would have expected the result to be 23 in both cases, because special character # omits zeros. How does the leading special character 0 affect the fraction part? (Tried to match/understand it with the BNF given in javadoc, but failed to do so.)

2 Answers
Related