summaryrefslogtreecommitdiffstats
path: root/icu/src/main/java
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2010-03-18 17:00:07 -0700
committerElliott Hughes <enh@google.com>2010-03-18 17:31:27 -0700
commit42db7d138547e3bba75cf6ed02b6a319e30004ae (patch)
treea03afd6a7aedd04aacb58d1e97f2f9ac51f21980 /icu/src/main/java
parentee7ff7aae7187c37cf9e6f77018323ed782d8828 (diff)
downloadlibcore-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/java')
-rw-r--r--icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java17
1 files changed, 17 insertions, 0 deletions
diff --git a/icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java b/icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java
index d1da72f..d46c2ec 100644
--- a/icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java
+++ b/icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java
@@ -20,6 +20,7 @@ import com.ibm.icu4jni.util.LocaleData;
import java.math.BigDecimal;
import java.math.BigInteger;
+import java.math.RoundingMode;
import java.text.AttributedCharacterIterator;
import java.text.AttributedString;
import java.text.DecimalFormatSymbols;
@@ -570,6 +571,21 @@ public class NativeDecimalFormat {
}
}
+ public void setRoundingMode(RoundingMode roundingMode, double roundingIncrement) {
+ final int nativeRoundingMode;
+ switch (roundingMode) {
+ case CEILING: nativeRoundingMode = 0; break;
+ case FLOOR: nativeRoundingMode = 1; break;
+ case DOWN: nativeRoundingMode = 2; break;
+ case UP: nativeRoundingMode = 3; break;
+ case HALF_EVEN: nativeRoundingMode = 4; break;
+ case HALF_DOWN: nativeRoundingMode = 5; break;
+ case HALF_UP: nativeRoundingMode = 6; break;
+ default: throw new AssertionError();
+ }
+ setRoundingMode(addr, nativeRoundingMode, roundingIncrement);
+ }
+
private static native void applyPatternImpl(int addr, boolean localized, String pattern);
private static native int cloneDecimalFormatImpl(int addr);
private static native void closeDecimalFormatImpl(int addr);
@@ -589,6 +605,7 @@ public class NativeDecimalFormat {
String nan, char patternSeparator, char percent, char perMill, char zeroDigit);
private static native void setSymbol(int addr, int symbol, String str);
private static native void setAttribute(int addr, int symbol, int i);
+ private static native void setRoundingMode(int addr, int roundingMode, double roundingIncrement);
private static native void setTextAttribute(int addr, int symbol, String str);
private static native String toPatternImpl(int addr, boolean localized);
}