My DecimalFormat is sometimes returning a '?' when trying to format(). Is there an input that would create this scenario?
For example:
DecimalFormat df = new DecimalFormat("#.####");
df.format(X); // output : '?'
What could X possibly be?
It's not a question mark, it's a U+FFFD REPLACEMENT CHARACTER, which is displayed as ? since it can't be mapped to the output encoding:
NaN is formatted as a string, which typically has a single character \uFFFD. This string is determined by the DecimalFormatSymbols object. This is the only value for which the prefixes and suffixes are not used.
Similarly, ? in representation of infinity is a U+221E INFINITY character (∞).
Infinity is formatted as a string, which typically has a single character \u221E, with the positive or negative prefixes and suffixes applied. The infinity string is determined by the DecimalFormatSymbols object.
See also:
DecimalFormat javadocIt'll return "?" if X is Float.NaN or Float.POSITIVE_INFINITY. It appears that Float.NEGATIVE_INFINITY returns "-?".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With