Fix issue when a currency symbol includes some special chars (like ".")

FEA: ItEr76S25CurrencyManagement
This commit is contained in:
Manuel Rego Casasnovas 2012-04-27 10:08:47 +02:00
parent cd2720147e
commit fb241900b7

View file

@ -24,6 +24,7 @@ package org.libreplan.web.common;
import static org.libreplan.web.I18nHelper._;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
@ -65,6 +66,12 @@ public class Util {
private static final Log LOG = LogFactory.getLog(Util.class);
/**
* Special chars from {@link DecimalFormat} class.
*/
private static final String[] DECIMAL_FORMAT_SPECIAL_CHARS = { "0", ",",
".", "\u2030", "%", "#", ";", "-" };
private Util() {
}
@ -656,7 +663,19 @@ public class Util {
* symbol
*/
public static String getMoneyFormat() {
return "###.## " + getCurrencySymbol();
return "###.## " + escapeDecimalFormatSpecialChars(getCurrencySymbol());
}
/**
* Escapes special chars used in {@link DecimalFormat} to define the number
* format that appear in the <code>currencySymbol</code>.
*/
private static String escapeDecimalFormatSpecialChars(String currencySymbol) {
for (String specialChar : DECIMAL_FORMAT_SPECIAL_CHARS) {
currencySymbol = currencySymbol.replace(specialChar, "'"
+ specialChar + "'");
}
return currencySymbol;
}
}