use of java.text.NumberFormat in project j2objc by google.
the class NumberFormatTest method test_setCurrency.
// Test the currency symbol is correctly taken from ICU. Verifies that the fractional digits
// are not updated because DecimalFormat.setCurrency agrees not to change it.
public void test_setCurrency() throws Exception {
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
// The Armenian Dram is a special case where the fractional digits are 0.
Currency amd = Currency.getInstance("AMD");
assertEquals(0, amd.getDefaultFractionDigits());
// Armenian Dram ISO 4217 code.
nf.setCurrency(amd);
// Check DecimalFormat has not taken the
assertEquals(2, nf.getMinimumFractionDigits());
// currency specific fractional digits.
assertEquals(2, nf.getMaximumFractionDigits());
assertEquals("AMD50.00", nf.format(50.00));
// Try and explicitly request fractional digits for the specified currency.
nf.setMaximumFractionDigits(amd.getDefaultFractionDigits());
assertEquals("AMD50", nf.format(50.00));
nf = NumberFormat.getCurrencyInstance(Locale.US);
// Euro sign.
nf.setCurrency(Currency.getInstance("EUR"));
assertEquals("€50.00", nf.format(50.00));
// Japanese Yen symbol.
nf.setCurrency(Currency.getInstance("JPY"));
assertEquals("¥50.00", nf.format(50.00));
// Swiss Franc ISO 4217 code.
nf.setCurrency(Currency.getInstance("CHF"));
assertEquals("CHF50.00", nf.format(50.00));
}
use of java.text.NumberFormat in project j2objc by google.
the class NumberFormatTest method test_custom_Number_gets_longValue.
// NumberFormat.format(Object, StringBuffer, FieldPosition) guarantees it calls doubleValue for
// custom Number subclasses.
public void test_custom_Number_gets_longValue() throws Exception {
class MyNumber extends Number {
public byte byteValue() {
throw new UnsupportedOperationException();
}
public double doubleValue() {
return 123;
}
public float floatValue() {
throw new UnsupportedOperationException();
}
public int intValue() {
throw new UnsupportedOperationException();
}
public long longValue() {
throw new UnsupportedOperationException();
}
public short shortValue() {
throw new UnsupportedOperationException();
}
public String toString() {
throw new UnsupportedOperationException();
}
}
NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
assertEquals("123", nf.format(new MyNumber()));
}
use of java.text.NumberFormat in project j2objc by google.
the class NumberFormatTest method test_getIntegerInstance_ar.
public void test_getIntegerInstance_ar() throws Exception {
// Previous versions of android use just the positive format string (ICU4C) although now we
// use '<positive_format>;<negative_format>' because of ICU4J denormalization.
NumberFormat numberFormat = NumberFormat.getNumberInstance(new Locale("ar"));
String patternNI = ((DecimalFormat) numberFormat).toPattern();
assertTrue("#,##0.###;-#,##0.###".equals(patternNI) || "#,##0.###".equals(patternNI));
NumberFormat integerFormat = NumberFormat.getIntegerInstance(new Locale("ar"));
String patternII = ((DecimalFormat) integerFormat).toPattern();
assertTrue("#,##0;-#,##0".equals(patternII) || "#,##0".equals(patternII));
}
use of java.text.NumberFormat in project j2objc by google.
the class NumberFormatTest method test_currencyFromLocale.
// Test to ensure currency formatting from specified locale works.
public void test_currencyFromLocale() {
// French locale formats with "," as separator and Euro symbol after a non-breaking space.
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.FRANCE);
assertEquals("50,00 €", nf.format(50));
// British locale uses pound sign with no spacing.
nf = NumberFormat.getCurrencyInstance(Locale.UK);
assertEquals("£50.00", nf.format(50));
}
use of java.text.NumberFormat in project j2objc by google.
the class NumberFormatTest method test_small_BigInteger_gets_longValue.
// NumberFormat.format(Object, StringBuffer, FieldPosition) guarantees it calls longValue for
// any BigInteger with a bitLength strictly less than 64.
public void test_small_BigInteger_gets_longValue() throws Exception {
class MyNumberFormat extends NumberFormat {
public StringBuffer format(double value, StringBuffer b, FieldPosition f) {
b.append("double");
return b;
}
public StringBuffer format(long value, StringBuffer b, FieldPosition f) {
b.append("long");
return b;
}
public Number parse(String string, ParsePosition p) {
throw new UnsupportedOperationException();
}
}
NumberFormat nf = new MyNumberFormat();
assertEquals("long", nf.format(BigInteger.valueOf(Long.MAX_VALUE)));
assertEquals("double", nf.format(BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE)));
assertEquals("long", nf.format(BigInteger.valueOf(Long.MIN_VALUE)));
assertEquals("double", nf.format(BigInteger.valueOf(Long.MIN_VALUE).subtract(BigInteger.ONE)));
}
Aggregations