commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bruno P. Kinoshita (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (VALIDATOR-433) BigDecimalValidator does not validate "()" negative currency uniformly for all locales
Date Tue, 21 Nov 2017 08:13:00 GMT

    [ https://issues.apache.org/jira/browse/VALIDATOR-433?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16260402#comment-16260402
] 

Bruno P. Kinoshita commented on VALIDATOR-433:
----------------------------------------------

Hi John, thanks for the test case, that helped.

There are different negative prefixes and negative suffixes, depending on the locale you use.
This is controlled by the JVM, not by Commons Validator, so not much can be done here.

The UK locale expects you to use "-£1,234.56". Here's a code that generates the list of locales
and their prefix/suffix pairs.

{code:java}
Locale[] locales = Locale.getAvailableLocales();
for (Locale locale : locales) {
    DecimalFormat nf = (DecimalFormat) NumberFormat.getCurrencyInstance(locale);
    String negativePrefix = nf.getNegativePrefix();
    String negativeSuffix = nf.getNegativeSuffix();
    System.out.println(String.format("%s---%s\t%s", negativePrefix, negativeSuffix, locale.getDisplayName()));
}
{code}

> BigDecimalValidator does not validate "()" negative currency uniformly for all locales
> --------------------------------------------------------------------------------------
>
>                 Key: VALIDATOR-433
>                 URL: https://issues.apache.org/jira/browse/VALIDATOR-433
>             Project: Commons Validator
>          Issue Type: Bug
>          Components: Routines
>    Affects Versions: 1.6
>         Environment: Windows 10, Tomcat 6, Java 8
>            Reporter: John DiPirro
>            Priority: Critical
>         Attachments: CurrencyValidatorTest.java, junitResults.jpg, screenshot-1.png
>
>
> Hi, 
> The following tests fail: 
> final String JAPAN_YEN = (new DecimalFormatSymbols(Locale.JAPAN)).getCurrencySymbol();

> final String CHINA_YEN = (new DecimalFormatSymbols(Locale.CHINA)).getCurrencySymbol();

> BigDecimal negative = new BigDecimal("-1234.56"); 
> assertEquals("Japan negative", negative, validator.validate("(" + JAPAN_YEN + "1,234.56)",
Locale.CHINA)); 
> assertEquals("China negative", negative, validator.validate("(" + CHINA_YEN + "1,234.56)",
Locale.CHINA)); 
> Please not that this test do not fail for other locales (US AND UK, for example). 
> Please advise on whether this is an issue, if there is a workaround, etc... 
> Regards, 
> John DiPirro



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message