diff options
Diffstat (limited to 'icu')
-rw-r--r-- | icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java | 17 | ||||
-rw-r--r-- | icu/src/main/native/NativeDecimalFormat.cpp | 9 |
2 files changed, 25 insertions, 1 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); } 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}, }; |