英文:
Java NumberFormat seams to be stuck on / permanently overriden to english format
问题
我正在尝试从字符串中解析德国的数字。这里是一个简单的示例:
String stringValue = "1,00";
double value = NumberFormat.getInstance(Locale.GERMANY).parse(stringValue).doubleValue();
// value = 100.0(来自命令行的本地设置,服务器 JDK)
// value = 1.0(来自命令行的本地设置,本地 JDK)
不知何故,格式始终停留在英文格式。我对这行代码进行了调试,并查看了symbols.decimalSeparator
,它仍然是点号。
我必须承认,只有在我使用公司服务器上的 JDK 运行应用程序时才能重现这种行为。在我自己的本地 JDK 上运行时,一切都正常,符合预期。所以也许服务器上的Locale
设置是英文,但这如何覆盖我硬编码的Locale.GERMANY
呢?
我们正在使用 Java 8。
<details>
<summary>英文:</summary>
I am trying to parse a german number from a string. Here is a minimal example:
```java
String stringValue = "1,00";
double value = NumberFormat.getInstance(Locale.GERMANY).parse(stringValue).doubleValue();
// value = 100.0 (locale machine from cmd, server jdk)
// value = 1.0 (locale machine from cmd, locale jdk)
Somehow the format is permanently stuck at an englisch formater. I debugged the line and had a look at the symbols.decimalSeperator
and it is still a dot.
I must admit, that I can only reproduce this behaviour if I run the application with a JDK from a server in our company. Running it with my locale JDK everything works fine and as expected. So maybe the locale Locale
on the server is englisch, but how can this override my hardcode Locale.GERMANY
?
We are using Java 8.
专注分享java语言的经验与见解,让所有开发者获益!
评论