switch (operand) {
case PLURAL_OPERAND_I:
- return static_cast<double>(toLong());
+ // Invert the negative sign if necessary
+ return static_cast<double>(isNegative() ? -toLong() : toLong());
case PLURAL_OPERAND_F:
return static_cast<double>(toFractionLong(true));
case PLURAL_OPERAND_T:
@Override
public String getName(ULocale locale, int nameStyle, String pluralCount, boolean[] isChoiceFormat) {
- if (nameStyle == PLURAL_LONG_NAME && subType.equals("XXX")) {
- // Plural in absence of a currency should return the symbol
- return symbol1;
- }
return super.getName(locale, nameStyle, pluralCount, isChoiceFormat);
}
switch (operand) {
case i:
- return toLong();
+ // Invert the negative sign if necessary
+ return isNegative() ? -toLong() : toLong();
case f:
return toFractionLong(true);
case t:
* Returns a long approximating the internal BCD. A long can only represent the integral part of the
* number.
*
- * @return A double representation of the internal BCD.
+ * @return A 64-bit integer representation of the internal BCD.
*/
public long toLong() {
long result = 0L;
/**
* Exception used for illegal number skeleton strings.
*
- * @author sffc
+ * @draft ICU 62
+ * @provisional This API might change or be removed in a future release.
+ * @see NumberFormatter
*/
public class SkeletonSyntaxException extends IllegalArgumentException {
private static final long serialVersionUID = 7733971331648360554L;
+ /**
+ * Construct a new SkeletonSyntaxException with information about the token at the point of failure.
+ *
+ * @draft ICU 62
+ * @provisional This API might change or be removed in a future release.
+ * @see NumberFormatter
+ */
public SkeletonSyntaxException(String message, CharSequence token) {
super("Syntax error in skeleton string: " + message + ": " + token);
}
+ /**
+ * Construct a new SkeletonSyntaxException with information about the token at the point of failure.
+ *
+ * @draft ICU 62
+ * @provisional This API might change or be removed in a future release.
+ * @see NumberFormatter
+ */
public SkeletonSyntaxException(String message, CharSequence token, Throwable cause) {
super("Syntax error in skeleton string: " + message + ": " + token, cause);
}
ULocale locale = new ULocale("en");
DecimalFormat nf = (DecimalFormat) NumberFormat.getInstance(locale, NumberFormat.PLURALCURRENCYSTYLE);
assertEquals(
- "Positive suffix should contain the single currency sign when no currency is set",
- " \u00A4",
+ "Positive suffix should contain the localized display name for currency XXX",
+ " (unknown currency)",
nf.getPositiveSuffix());
}
}
import java.util.Date;
import java.util.Locale;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.ibm.icu.text.DecimalFormat;
import com.ibm.icu.text.DecimalFormatSymbols;
import com.ibm.icu.text.NumberFormat;
+import com.ibm.icu.util.Currency;
import com.ibm.icu.util.GregorianCalendar;
import com.ibm.icu.util.ULocale;
import com.ibm.icu.util.VersionInfo;
logln("Long.MIN_VALUE : " + df.parse(str, new ParsePosition(0)).toString());
df.setMultiplier(100);
Number num = df.parse(str, new ParsePosition(0));
- if (num.doubleValue() != -9.223372036854776E16) {
- errln("Bug 4092561 test failed when multiplier is set to not 1.");
- }
+ assertEquals("Bug 4092561 test failed when multiplier is set to not 1.", -9.223372036854776E16, num.doubleValue());
Locale.setDefault(savedLocale);
}
* 1) Make sure that all currency formats use the generic currency symbol.
* 2) Make sure we get the same results using the generic symbol or a
* hard-coded one.
+ *
+ * ICU 62: DecimalFormatSymbols currency symbol has long been deprecated.
+ * In the absence of a user-specified currency, XXX is used instead.
*/
@Test
+ @Ignore
public void Test4122840()
{
Locale[] locales = NumberFormat.getAvailableLocales();
String pat = df.toPattern();
DecimalFormatSymbols symb = new DecimalFormatSymbols(avail[i]);
DecimalFormat f2 = new DecimalFormat(pat, symb);
- f2.setCurrency(df.getCurrency()); // Currency does not travel with the pattern string
+ if (df.getCurrency() != Currency.getInstance("XXX") && j == 1) {
+ // Currency does not travel with the pattern string
+ f2.setCurrency(df.getCurrency());
+ }
if (!df.equals(f2)) {
errln("FAIL: " + avail[i] + " #" + j + " -> \"" + pat +
- "\" -> \"" + f2.toPattern() + '"');
+ "\" -> \"" + f2.toPattern() + "\" for case " + j);
}
// Test toLocalizedPattern/applyLocalizedPattern round trip
String formatStr = "At <time> on {1,date}, you made a {2} of {0,number,currency}.";
// {sfb} to get $, would need Locale::US, not Locale::ENGLISH
// Just use unlocalized currency symbol.
+ // ICU 62: use the unknown currency symbol XXX.
//String compareStrEng = "At <time> on Aug 8, 1997, you made a deposit of $456.83.";
String compareStrEng = "At <time> on Aug 8, 1997, you made a deposit of ";
- compareStrEng += '\u00a4';
+ compareStrEng += "XXX\u00a0";
compareStrEng += "456.83.";
// {sfb} to get DM, would need Locale::GERMANY, not Locale::GERMAN
// Just use unlocalized currency symbol.
//String compareStrGer = "At <time> on 08.08.1997, you made a deposit of 456,83 DM.";
String compareStrGer = "At <time> on 08.08.1997, you made a deposit of ";
compareStrGer += "456,83\u00a0";
- compareStrGer += '\u00a4';
+ compareStrGer += "XXX";
compareStrGer += ".";
MessageFormat msg = new MessageFormat(formatStr, Locale.ENGLISH);
String compareStr = "At <time> on Aug 8, 1997, you made a deposit of $456.83.";
// the date being German-style, but the currency being English-style
String compareStr2 = "At <time> on 08.08.1997, you made a deposit of ";
- compareStr2 += '\u00a4';
+ compareStr2 += "XXX\u00A0";
compareStr2 += "456.83.";
// both date and currency formats are German-style
String compareStr3 = "At <time> on 08.08.1997, you made a deposit of ";
compareStr3 += "456,83\u00a0";
- compareStr3 += '\u00a4';
+ compareStr3 += "XXX";
compareStr3 += ".";
MessageFormat msg = new MessageFormat(formatStr, ULocale.US);
import com.ibm.icu.impl.IllegalIcuArgumentException;
import com.ibm.icu.impl.InvalidFormatException;
import com.ibm.icu.impl.locale.LocaleSyntaxException;
+import com.ibm.icu.number.SkeletonSyntaxException;
import com.ibm.icu.text.ArabicShapingException;
import com.ibm.icu.text.StringPrepParseException;
import com.ibm.icu.util.IllformedLocaleException;
return exceptions;
}
}
+
+ static class SkeletonSyntaxExceptionHandler extends ExceptionHandler
+ {
+ public Object[] getTestObjects()
+ {
+ SkeletonSyntaxException[] exceptions = {
+ new SkeletonSyntaxException("Bad number skeleton", "[foo]")
+ };
+ return exceptions;
+ }
+ }
}
map.put("com.ibm.icu.impl.number.Properties", new PropertiesTest.ICU59PropertiesHandler());
map.put("com.ibm.icu.impl.number.DecimalFormatProperties", new PropertiesTest.PropertiesHandler());
map.put("com.ibm.icu.impl.number.CustomSymbolCurrency", new CurrencyHandler());
+ map.put("com.ibm.icu.number.SkeletonSyntaxException", new ExceptionHandler.SkeletonSyntaxExceptionHandler());
map.put("com.ibm.icu.util.ICUException", new ICUExceptionHandler());
map.put("com.ibm.icu.util.ICUUncheckedIOException", new ICUUncheckedIOExceptionHandler());