Locale for Norwegian, Bokmal(Norway) issue

感情迁移 提交于 2019-12-08 07:48:48

问题


I am facing problem while opening a downloaded CSV file in Excel under window 7 for above locale. Sometime the number is treated as date and all the cells are misaligned and formatted incorrectly.

I have written code for CSV download with the localized format. It's working perfectly for all the regions except this one.

I invested the issue and it came to know that there is a mismatch between format defined on Windows 7 system and locale retrieved from ServletRequest#getLocale() for Norwegian, Bokmal(Norway).

Here is my code:

Servlet:

Locale locale = request.getLocale();
DecimalFormat decimalFormatter=(DecimalFormat)DecimalFormat.getInstance(locale);

locale.getDisplayCountry();            // empty string
decimalFormatter.toLocalizedPattern(); // #,##0.###
locale.getDisplayLanguage();           // Norwegian Bokmål
locale.toString();                     // nb

Now look at the Digit grouping symbol and Decimal symbol in above code.


My Question: How can I get the correct number format pattern as it is on Windows 7?

Here is the screenshot of the Languages set in Firefox.

Here is the screenshot of Language and Region on Windows 7 where for numbers Digit grouping symbol is a single space and Decimal symbol is a comma.


回答1:


The language of the decimal format should work straight "out of the box".

    Locale locale = new Locale("nb");
    DecimalFormat decimalFormatter=(DecimalFormat) DecimalFormat.getInstance(locale);

    System.out.println(locale.getDisplayCountry());           
    System.out.println(decimalFormatter.toLocalizedPattern()); 
    System.out.println(decimalFormatter.toLocalizedPattern()); 
    System.out.println(locale.getDisplayLanguage());        

    System.out.println(decimalFormatter.format(1234.567));

Yields this result for me:

(empty)
# ##0,###
# ##0,###
Norwegian Bokmål
1 234,567

The decimal format is not controlled by the windows settings though, tried changing decimal separator to . in windows, with no effect.



来源:https://stackoverflow.com/questions/23610651/locale-for-norwegian-bokmalnorway-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!