diff options
author | Elliott Hughes <enh@google.com> | 2010-01-27 15:31:17 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2010-01-27 16:18:59 -0800 |
commit | d7e81f7408fb84307d7792b7e3ab8c5a510b294b (patch) | |
tree | 6decad96fd626ac83e10b9788412acc89dab0b83 /icu/src/main | |
parent | 820dd9b89746b3e3005bd5d23176cde1a69048b7 (diff) | |
download | libcore-d7e81f7408fb84307d7792b7e3ab8c5a510b294b.zip libcore-d7e81f7408fb84307d7792b7e3ab8c5a510b294b.tar.gz libcore-d7e81f7408fb84307d7792b7e3ab8c5a510b294b.tar.bz2 |
Fix NumberFormat's behavior with BigInteger and custom Number subclasses.
Also remove a few bits of cruft I ran across, and stop duplicating the
documentation between NumberFormat and DecimalFormat.
Bug: 2387934
Diffstat (limited to 'icu/src/main')
-rw-r--r-- | icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java | 44 |
1 files changed, 27 insertions, 17 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 fd22ed0..c8fc252 100644 --- a/icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java +++ b/icu/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java @@ -218,7 +218,32 @@ public class NativeDecimalFormat { // Get new value by multiplying multiplier. return valBigDecimal.multiply(multiplierBigDecimal); } - + + public StringBuffer formatBigDecimal(BigDecimal value, StringBuffer buffer, FieldPosition field) { + if (buffer == null || field == null) { + throw new NullPointerException(); + } + if (getMultiplier() != 1) { + value = applyMultiplier(value); + } + StringBuilder val = new StringBuilder(); + val.append(value.unscaledValue().toString(10)); + int scale = value.scale(); + scale = makeScalePositive(scale, val); + String fieldType = getFieldType(field.getFieldAttribute()); + String result = format(this.addr, val.toString(), field, fieldType, null, scale); + return buffer.append(result); + } + + public StringBuffer formatBigInteger(BigInteger value, StringBuffer buffer, FieldPosition field) { + if (buffer == null || field == null) { + throw new NullPointerException(); + } + String fieldType = getFieldType(field.getFieldAttribute()); + String result = format(this.addr, value.toString(10), field, fieldType, null, 0); + return buffer.append(result); + } + /* public StringBuffer format(Object value, StringBuffer buffer, FieldPosition field) { if (!(value instanceof Number)) { throw new IllegalArgumentException(); @@ -228,21 +253,6 @@ public class NativeDecimalFormat { } String fieldType = getFieldType(field.getFieldAttribute()); Number number = (Number) value; - if (number instanceof BigInteger) { - BigInteger valBigInteger = (BigInteger) number; - String result = format(this.addr, valBigInteger.toString(10), field, fieldType, null, 0); - return buffer.append(result); - } else if (number instanceof BigDecimal) { - BigDecimal valBigDecimal = (BigDecimal) number; - if (getMultiplier() != 1) { - valBigDecimal = applyMultiplier(valBigDecimal); - } - StringBuilder val = new StringBuilder(); - val.append(valBigDecimal.unscaledValue().toString(10)); - int scale = valBigDecimal.scale(); - scale = makeScalePositive(scale, val); - String result = format(this.addr, val.toString(), field, fieldType, null, scale); - return buffer.append(result); } else if (number instanceof Double || number instanceof Float) { double dv = number.doubleValue(); String result = format(this.addr, dv, field, fieldType, null); @@ -253,7 +263,7 @@ public class NativeDecimalFormat { return buffer.append(result); } } - +*/ public StringBuffer format(long value, StringBuffer buffer, FieldPosition field) { if (buffer == null || field == null) { throw new NullPointerException(); |