diff options
author | Elliott Hughes <enh@google.com> | 2010-03-18 17:00:07 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2010-03-18 17:31:27 -0700 |
commit | 42db7d138547e3bba75cf6ed02b6a319e30004ae (patch) | |
tree | a03afd6a7aedd04aacb58d1e97f2f9ac51f21980 /icu/src/main/native/NativeDecimalFormat.cpp | |
parent | ee7ff7aae7187c37cf9e6f77018323ed782d8828 (diff) | |
download | libcore-42db7d138547e3bba75cf6ed02b6a319e30004ae.zip libcore-42db7d138547e3bba75cf6ed02b6a319e30004ae.tar.gz libcore-42db7d138547e3bba75cf6ed02b6a319e30004ae.tar.bz2 |
Add's Java 6's DecimalFormat.setRoundingMode (et cetera).
Format and NumberFormat's bogusly-public constructors became protected with
Java 6. DecimalFormat gained more control over rounding behavior. There's a
slight mismatch with our ICU4C-based implementation in that ICU4C doesn't
support RoundingMode.UNNECESSARY, so I've had to fake that (but I doubt it's
used much, if at all).
I've pulled out the obviously Android-specific tests from the harmony
DecimalFormatTest.java, but I've only brought back the rounding mode changes
from the current harmony code to avoid the new tests' dependencies. I've also
added one new test of my own, to check that setMaximumFractionDigits affects
rounding as it should (since the harmony tests don't test this, and it's
somewhat subtle).
Bug: 2497395
Change-Id: Ifafc8bb051e078ead988073281f5c33f0aeb130a
Diffstat (limited to 'icu/src/main/native/NativeDecimalFormat.cpp')
-rw-r--r-- | icu/src/main/native/NativeDecimalFormat.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/icu/src/main/native/NativeDecimalFormat.cpp b/icu/src/main/native/NativeDecimalFormat.cpp index 413ffdd..b62e5b1 100644 --- a/icu/src/main/native/NativeDecimalFormat.cpp +++ b/icu/src/main/native/NativeDecimalFormat.cpp @@ -103,10 +103,16 @@ static jint openDecimalFormatImpl(JNIEnv* env, jclass clazz, jstring pattern0, return static_cast<jint>(reinterpret_cast<uintptr_t>(fmt)); } -static void closeDecimalFormatImpl(JNIEnv *env, jclass clazz, jint addr) { +static void closeDecimalFormatImpl(JNIEnv* env, jclass, jint addr) { delete toDecimalFormat(addr); } +static void setRoundingMode(JNIEnv* env, jclass, jint addr, jint mode, jdouble increment) { + DecimalFormat* fmt = toDecimalFormat(addr); + fmt->setRoundingMode(static_cast<DecimalFormat::ERoundingMode>(mode)); + fmt->setRoundingIncrement(increment); +} + static void setSymbol(JNIEnv* env, jclass, jint addr, jint symbol, jstring s) { const UChar* chars = env->GetStringChars(s, NULL); const int32_t charCount = env->GetStringLength(s); @@ -593,6 +599,7 @@ static JNINativeMethod gMethods[] = { {"setAttribute", "(III)V", (void*) setAttribute}, {"setDecimalFormatSymbols", "(ILjava/lang/String;CCCLjava/lang/String;Ljava/lang/String;CCLjava/lang/String;CCCC)V", (void*) setDecimalFormatSymbols}, {"setSymbol", "(IILjava/lang/String;)V", (void*) setSymbol}, + {"setRoundingMode", "(IID)V", (void*) setRoundingMode}, {"setTextAttribute", "(IILjava/lang/String;)V", (void*) setTextAttribute}, {"toPatternImpl", "(IZ)Ljava/lang/String;", (void*) toPatternImpl}, }; |