Java的NumberFormat似乎被固定在英文格式上,无法永久覆盖。

huangapple 未分类评论47阅读模式
英文:

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 = &quot;1,00&quot;;
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.

huangapple
  • 本文由 发表于 2020年5月5日 14:06:25
  • 转载请务必保留本文链接:https://java.coder-hub.com/61606766.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定