挪威语的语言环境,Bokmal(Norway)问题 [英] Locale for Norwegian, Bokmal(Norway) issue

查看:197
本文介绍了挪威语的语言环境,Bokmal(Norway)问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在上述区域设置的窗口7下的Excel中打开下载的CSV文件时,我遇到了问题.有时,该数字被视为日期,并且所有单元格均未对齐且格式不正确.

我已经用本地化格式编写了CSV下载代码.除这一地区外,它在所有地区均正常运行.

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

我投资了这个问题,结果发现Windows 7系统上定义的格式与从

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).

这是我的代码:

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.

我的问题:如何获得Windows 7上正确的数字格式模式?

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

这是Firefox中设置的语言的屏幕截图.

Here is the screenshot of the Languages set in Firefox.

以下是Windows 7上语言和区域"的屏幕截图,其中数字数字分组符号是单个空格,十进制符号是逗号.

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.

推荐答案

十进制格式的语言应开箱即用".

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));

为我带来了这个结果:

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

尽管十进制格式不受Windows设置的控制,但尝试将十进制分隔符更改为Windows中的.,但无效.

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

这篇关于挪威语的语言环境,Bokmal(Norway)问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆