use of android.icu.text.DecimalFormat in project j2objc by google.
the class MyNumberFormat method Test4087535.
/**
* DecimalFormat.format() incorrectly formats 0.0
*/
@Test
public void Test4087535() {
DecimalFormat df = new DecimalFormat();
df.setMinimumIntegerDigits(0);
double n = 0;
String buffer = new String();
buffer = df.format(n);
if (buffer.length() == 0)
errln(n + ": '" + buffer + "'");
n = 0.1;
buffer = df.format(n);
if (buffer.length() == 0)
errln(n + ": '" + buffer + "'");
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class MyNumberFormat method Test4086575.
/**
* A space as a group separator for localized pattern causes
* wrong format. WorkAround : use non-breaking space.
*/
@Test
public void Test4086575() {
NumberFormat nf = NumberFormat.getInstance(Locale.FRANCE);
logln("nf toPattern1: " + ((DecimalFormat) nf).toPattern());
logln("nf toLocPattern1: " + ((DecimalFormat) nf).toLocalizedPattern());
// No group separator
logln("...applyLocalizedPattern ###,00;(###,00) ");
((DecimalFormat) nf).applyLocalizedPattern("###,00;(###,00)");
logln("nf toPattern2: " + ((DecimalFormat) nf).toPattern());
logln("nf toLocPattern2: " + ((DecimalFormat) nf).toLocalizedPattern());
// 1234,00
logln("nf: " + nf.format(1234));
// (1234,00)
logln("nf: " + nf.format(-1234));
// Space as group separator
logln("...applyLocalizedPattern # ###,00;(# ###,00) ");
((DecimalFormat) nf).applyLocalizedPattern("#\u00a0###,00;(#\u00a0###,00)");
logln("nf toPattern2: " + ((DecimalFormat) nf).toPattern());
logln("nf toLocPattern2: " + ((DecimalFormat) nf).toLocalizedPattern());
String buffer = nf.format(1234);
if (!buffer.equals("1\u00a0234,00"))
// Expect 1 234,00
errln("nf : " + buffer);
buffer = nf.format(-1234);
if (!buffer.equals("(1\u00a0234,00)"))
// Expect (1 234,00)
errln("nf : " + buffer);
// Erroneously prints:
// 1234,00 ,
// (1234,00 ,)
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class MyNumberFormat method Test4087245.
/**
* DecimalFormatSymbols should be cloned in the ctor DecimalFormat.
* DecimalFormat(String, DecimalFormatSymbols).
*/
@Test
public void Test4087245() {
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
DecimalFormat df = new DecimalFormat("#,##0.0", symbols);
long n = 123;
StringBuffer buf1 = new StringBuffer();
StringBuffer buf2 = new StringBuffer();
logln("format(" + n + ") = " + df.format(n, buf1, new FieldPosition(0)));
// change value of field
symbols.setDecimalSeparator('p');
logln("format(" + n + ") = " + df.format(n, buf2, new FieldPosition(0)));
if (!buf1.toString().equals(buf2.toString()))
errln("Test for bug 4087245 failed");
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class MyNumberFormat method Test4108738.
/**
* DecimalFormat.parse incorrectly works with a group separator.
*/
@Test
public void Test4108738() {
DecimalFormat df = new DecimalFormat("#,##0.###", new DecimalFormatSymbols(java.util.Locale.US));
String text = "1.222,111";
Number num = df.parse(text, new ParsePosition(0));
if (!num.toString().equals("1.222"))
errln("\"" + text + "\" is parsed as " + num);
text = "1.222x111";
num = df.parse(text, new ParsePosition(0));
if (!num.toString().equals("1.222"))
errln("\"" + text + "\" is parsed as " + num);
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class MyNumberFormat method Test4170798.
/**
* DecimalFormat.parse() fails when ParseIntegerOnly set to true
*/
@Test
public void Test4170798() {
Locale savedLocale = Locale.getDefault();
Locale.setDefault(Locale.US);
DecimalFormat df = new DecimalFormat();
df.setParseIntegerOnly(true);
Number n = df.parse("-0.0", new ParsePosition(0));
if (!(n instanceof Double) || n.intValue() != 0) {
errln("FAIL: parse(\"-0.0\") returns " + n + " (" + n.getClass().getName() + ')');
}
Locale.setDefault(savedLocale);
}
Aggregations