History log of /libcore/luni/src/main/java/java/text/DecimalFormat.java
Revision Date Author Comments
936306df62d7d44a806fbeb789c6432e7c325981 22-Oct-2014 smain@google.com <smain@google.com> autoclose all <a name> tags so they don't disappear on web site

<a> tags with the name attribute---used to create a page anchor---must be
closed immediately and not contain any text because, in order to make the
appropriate content visible below the site's "sticky header" when the anchor
is followed, CSS is used to hide the <a name> element and position it
up higher by an offset equal to the height of the sticky header.

So, do not place text inside an <a> tag with the name attribute.

Change-Id: Icae1b1f0716aa02d003f921b8e430ad3c99f26d0
8d07b07a3ed315c2e1c469d3769cf1df3f49e58b 18-Jun-2014 Neil Fuller <nfuller@google.com> Fix for currency symbol coming from the default locale

NumberFormat.setCurrency() (actually DecimalFormat) was using
currency.getSymbol() without passing the format's locale. This
caused the default Locale to be used to look up the symbol.

The fix uses the format locale, not the default. A test has
been added to demonstrate the problem / fix.

To avoid having the NativeDecimalFormat know about the locale class,
the symbol is passed as an argument rather than the Currency object.
This is an internal API.

Making this change showed an issue with Currency.getSymbol():
For Locales without a country the currency code would be returned
and not a symbol.

ICU provides language-level symbols so this was not the best
we could do. Since the code was previously using the default
Locale, and the default locale usually has a country it was
not previously obvious.

testBug71369 broke because of this second issue. The code is also
fixed here.

This was discovered while investigating bug 71369 but is not
related.

Change-Id: If0ce280aefb042fe8f7ca126cced090b9268a866
c96651d01dc87a20aa718d60feaff6611451852e 09-Apr-2014 Neil Fuller <nfuller@google.com> Change DecimalFormat.setRoundingMode() behavior to stay in spec

The serialization tests revealed that some DecimalFormat instances
could not be round-tripped. The reason is that the setRoundingMode()
method was setting a non-zero rounding increment, which cannot
be persisted, and also creates patterns that are outside of the
DecimalFormat spec.

Addressed the fact that ICU4C appears to support
RoundingMode.UNNECESSARY now by deleting special-case code.

Changed SerializationStressTest to use canonical DecimalFormat
patterns:

The ones chosen had a couple things that were not ideal:
1) Putting '-' in quotes causes ICU (for non-obvious reasons)
treat the negative pattern prefix as not being default. Default
in this case means "the positive prefix with a preceding '-'.
Removing the quotes meant it would recognize the pattern as
not needing everything after ;., so the pattern would be shrunk.
2) The positive pattern was also not one ICU could deal with
fully. ICU changed "#.#" to "#0.#" at parse time (which can be
corrected with a setMinimumIntegerDigits(0)). It's not clear why
ICU cannot deal with parsing "#.#" when it can produce it, but
there is a long comment in decimfmt.cc suggesting it is
intentional and to avoid format producing empty strings.

The pattern has been changed to one that ICU can handle and would
choose when the various serialized fields are read back. This is
necessary because NativeDecimalFormat compares the patterns and
not just the serialized fields. Leaving the pattern check part of
equals() means that two non-spec patterns will not be considered
equal(), which is important while Android allows non-spec patterns.
Restricting support in DecimalFormat to the documented subset of
characters is not worth the effort and may cause problems
elsewhere.

Change-Id: I2de588458b86619733c0dc1692d526f179059910
Bug: 11668227
74473971cc9d960376295fbcc430320c9ed62991 29-Aug-2013 Elliott Hughes <enh@google.com> Fix harmony java.text test failures.

There were plenty of bad tests here, but there were some real bugs too.

* DecimalFormat was only handling RoundingMode.UNNECESSARY for double
formatting.

* DecimalFormat was not ensuring that it's superclass' fields were
being correctly updated.

* NumberFormat was throwing NPE for a null object because of an
improved detail message, despite being specified to throw IAE.

* We weren't mapping NumberFormat.Field instances to the corresponding icu4c
UNUM_x_FIELD constant, so we weren't actually setting FieldPosition
objects correctly.

* SimpleDateFormat was not formatting milliseconds correctly with 'S'.

* NativeDecimalFormat wasn't handling JNI NewString OOME correctly.

Bug: 2528220
Bug: 3056865
Bug: 3057080
Bug: 3057090
Change-Id: Iac11f902f2e9649e596e7e7b7bc501b13e956fca
34a3a0501220dd62b88ddb4a355bad46b15c25a2 21-Sep-2012 Elliott Hughes <enh@google.com> Fix a native memory leak in SimpleDateFormat cloning.

We didn't use the regular finalization idiom in NativeDecimalFormat because
Formatter used to create a lot of these objects, and we wanted to be able to
close them manually rather than clogging up the GC. We've since rewritten
the Formatter code so this is no longer relevant, but we left the finalization
in the wrong class.

Tested with a "while (true) sdf.clone();" loop and ps(1).

Bug: http://code.google.com/p/android/issues/detail?id=37607
Change-Id: I0c435edf8c1bced00ebf04bd7187883344e971e7
d43b9ef11a1095967a3396b246639b563e1a4128 12-Sep-2012 Kenny Root <kroot@google.com> Add consistent reasons for NullPointerException

Semi-automated replacement of empty and non-conforming
NullPointerException reason messages.

(cherry-pick of 86acc043d3334651ee26c65467d78d6cefedd397.)

Change-Id: I6d893979f5c20a50e841e32af9fd7b2d8bc9d54d
86acc043d3334651ee26c65467d78d6cefedd397 12-Sep-2012 Kenny Root <kroot@google.com> Add consistent reasons for NullPointerException

Semi-automated replacement of empty and non-conforming
NullPointerException reason messages.

Change-Id: Iedeb4b21949e973c4042ce5982dda315f2e785e1
28eb98ecd43c27702e85b0561e040e2da10320a6 05-Feb-2011 Elliott Hughes <enh@google.com> Fix serialization of DecimalFormatSymbols.

Missing 'final' on the serialPersistentFields declaration meant we were
falling back to reflection, and 'exponential' isn't actually a field.

I've checked all the other serialPersistentFields fields, and put them
in a canonical form. There were no other errors.

I'll do two other related changes: I'll replace confusing use of Character.TYPE
with char.class (and so forth), and I'll backport the active ingredient from
this change so it's fixed in honeycomb-mr1.

Bug: http://code.google.com/p/android/issues/detail?id=14495
Change-Id: I954da649ad597450bee54957dc0e3d3aa9d151dd
fb0ec0e650bf8be35acb0d47da0311a7c446aa33 14-Jan-2011 Elliott Hughes <enh@google.com> Remove useless android-changed comments.

I've changed useful ones to regular comments or TODOs, as appropriate.

I've left ones in code like java.util.concurrent where we really are
tracking an upstream source, making the change markers useful.

I've left a handful of others where I intend to actually investigate
the implied TODOs before deciding how to resolve them.

Change-Id: Iaf71059b818596351cf8ee5a3cf3c85586051fa6
1c4b8eb0aebfe7f99c10fb1d01716946e8e74ad7 07-Jan-2011 Elliott Hughes <enh@google.com> Remove @SuppressWarnings("nls") cruft.

Also rewrite a couple of toString methods for clarity.

Change-Id: Ic6e8c474ef87e0c0550eea2daed611ae41118229
b46dab348e2007bc08abaf7ecae34d89a2474e50 09-Dec-2010 Elliott Hughes <enh@google.com> Rewrite all backwards comparisons.

Strictly, all the ones I could find. This is everything with 0 or null on the
left-hand side.

Note that this touches several incorrect bounds checks, which I haven't fixed:
I'm going to come back and finish that independent cleanup separately.

Change-Id: Ibdb054b53df9aace47c7d2a00ff19122190053e8
5501a3d4b3d7657c183ed5446fe67fa011fbf70b 03-Dec-2010 Elliott Hughes <enh@google.com> Comments/javadoc should be in en_US, not en_CA.

Change-Id: Ie9dde4971e0a6a8dadd14af43d631158fc488cd8
c27a366a89e470690e99374b15270e7b9169ade1 02-Oct-2010 Elliott Hughes <enh@google.com> More icu4jni reshuffling.

Bug: 3045778
Change-Id: Iafb367f97d1fb169c6106adad0525cfcc0e10f25
162b0775772fa66b7eb634760a8159a60c1ddcea 02-Oct-2010 Elliott Hughes <enh@google.com> Move more stuff out of icu4jni; ICU and LocaleData.

Bug: 3045778
Change-Id: I59fd27920a2da9a42b29fd79b8d81bdaabdef8cd
e2f58c9501eac730d048199906dc41fe8e4cd6e9 29-Sep-2010 Brian Carlstrom <bdc@google.com> Scrub missing calls to super.finalize()

Bug: 3024226
Change-Id: I6642cb9d4929ba72244529efe4ebdfa595ae4fa7
46cb23aaaba1b0553d02d32713abad97bd4b0428 16-Sep-2010 Elliott Hughes <enh@google.com> Return char[] instead of String from NativeDecimalFormat.

One last little speedup for Formatter %f before I call it a day for now...

Bug: 2934304
Change-Id: I9edd02d1ba8dc40a2b28fea34d7bccf95eeb56ab
3e6f49bbb915b880afe104ec784c66bda55da450 25-Aug-2010 Elliott Hughes <enh@google.com> Double the speed of %.2f in Formatter.

Primarily this works by going straight to the NativeDecimalFormat. This
cuts down on a bunch of objects we don't actually need. Changing
NativeDecimalFormat to not have a finalizer means we can also relieve
the GC of all the finalization work.

This also fixes a few test failures I ran across. The , flag and digit
localization aren't mutually exclusive, and BigDecimal (a) can't represent
NaN or either infinity, but (b) returns infinities from doubleValue if the
BigDecimal is out of double's range; this made our check for special
numbers in transformFromFloat wrong.

[cherry-picked 5f509be2576f2817856413301ca8135f6ee20b30 from dalvik-dev to gingerbread]

Bug: 2934304
1d58625189328f29c10fa98d52512ee6cf8cc641 26-Aug-2010 Ben Dodson <bjdodson@google.com> Update for changes to @code processing

Change-Id: Ifb7dbe3105bdef15dadb84740845a71b019d62e3
5f509be2576f2817856413301ca8135f6ee20b30 25-Aug-2010 Elliott Hughes <enh@google.com> Double the speed of %.2f in Formatter.

Primarily this works by going straight to the NativeDecimalFormat. This
cuts down on a bunch of objects we don't actually need. Changing
NativeDecimalFormat to not have a finalizer means we can also relieve
the GC of all the finalization work.

This also fixes a few test failures I ran across. The , flag and digit
localization aren't mutually exclusive, and BigDecimal (a) can't represent
NaN or either infinity, but (b) returns infinities from doubleValue if the
BigDecimal is out of double's range; this made our check for special
numbers in transformFromFloat wrong.

Bug: 2934304
Change-Id: I5aa38fbb2f775c0ac6728f8a70c8874c134155c0
705462a2b003b2eeed90bf3cebe0871e02554cbd 12-Aug-2010 Elliott Hughes <enh@google.com> Minor documentation improvements.

Fix unqualified uses of SimpleDateFormat in TimeZone.java, explain how to use
getPercentageInstance (http://code.google.com/p/android/issues/detail?id=10333),
add an explicit test to make sure no-one accidentally "fixes" that
odd-but-correct behavior, and remove an example from the DecimalFormat
documentation that doesn't really clarify anything.

Bug: http://code.google.com/p/android/issues/detail?id=10333
Change-Id: I52f22d817c7c6c32ad38fb6953fbe909a76f8943
7365de1056414750d0a7d1fdd26025fd247f0d04 12-Aug-2010 Jesse Wilson <jessewilson@google.com> Sorting imports.

Change-Id: I8347bc625480a1c37a1ed9976193ddfedeb00bbc
947eeb80f985827209c9500851e288504d58ec2e 03-Jun-2010 claireho <chinglanho@gmail.com> ICU4.4.1 upgrade
1. Replaced the temp Android patch for BigDecimal support
with ICU APIs.
2. Changed ICU.cpp for resource re-structure in ICU4.4 release.
3. Fixed the test data for NumberFormat test caused by the locale
data changes.

Change-Id: I307e798f1a135a5024a693d23363733d020ed22f
162a12c1442641a95fe95859fa4e561b22db049f 25-May-2010 Elliott Hughes <enh@google.com> Remove @hide from Java 6 API.

I've left the two new spi packages @hidden, because I think we shouldn't
support them without convincing demand from developers (and I don't
believe there could be such a thing --- they just don't make sense, and
if we add anything, it should be the ability to provide extra ICU data).

Also fix a handful of javadoc syntax errors in Arrays.java and TreeMap.java.

Bug: 2497395
Change-Id: I4176b72daff0face4ed6c7ee1d1f4267d52006b4
f33eae7e84eb6d3b0f4e86b59605bb3de73009f3 13-May-2010 Elliott Hughes <enh@google.com> Remove all trailing whitespace from the dalvik team-maintained parts of libcore.

Gentlemen, you may now set your editors to "strip trailing whitespace"...

Change-Id: I85b2f6c80e5fbef1af6cab11789790b078c11b1b
fd6bb3510c2f94d636f3572dcf5f7f4dcd1a2726 13-May-2010 Elliott Hughes <enh@google.com> Remove //$NON-NLS-\d$ cruft.

Mostly done by perl(1), with manual cleanup of the few misspelled instances.
This makes our trailing whitespace slightly worse, but I'll fix all that with
a follow-on change.

Change-Id: I0b4ca98819be6f9519c4ba980d759bd1ee1a0303
cec4dd4b1d33f78997603d0f89c0d0e56e64dbcd 26-Apr-2010 Peter Hallam <peterhal@google.com> merge more modules into luni