RTL语言环境中的负数数字问题像阿拉伯语一样

发布于 2025-02-10 02:19:30 字数 256 浏览 1 评论 0 原文

Locale locale = new Locale("ar", "AE");
NumberFormat format = NumberFormat.getNumberInstance(locale);                
System.out.println(format.parse("55-"));

上面的代码以JDK 8返回-55,并以11返回55。知道为什么这会发生变化吗?如何用Java 11中的阿拉伯语(RTL)解析负数?

Locale locale = new Locale("ar", "AE");
NumberFormat format = NumberFormat.getNumberInstance(locale);                
System.out.println(format.parse("55-"));

The above code returns -55 with JDK 8 and returns 55 with 11. Also format.parse("-55") throws parseException. Any idea why is this change? How to parse negative numbers in Arabic (RTL) with java 11?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

皇甫轩 2025-02-17 02:19:30

从Java 9开始,JDK优先考虑CLDR LocaLE数据。 (Unicode Common Locale数据存储库)

如果要获得Java 8中的行为,则可以使用命令行参数-djava.locale.locale.providers = compat,spi,cldr

,它将使用旧的“ compat” compat“ compat” compat“ compat” locale数据,仅在Compat没有用于您的语言环境的位置数据时才使用SPI或CLDR。

同样的Java变化也会影响瑞典的解析,一周的第一天,在德国,可能还有许多其他事情。

Starting with Java 9, the JDK gives priority to CLDR locale data. (Unicode Common Locale Data Repository)

If you want to get the behavior seen in Java 8, you can use command-line parameter -Djava.locale.providers=COMPAT,SPI,CLDR

With this, it will use the older "COMPAT" locale data and only use SPI or CLDR if COMPAT doesn't have locale data for your locale.

https://www.oracle.com/java/technologies/javase/9-relnotes.html#JDK-8008577

This same java change also affects parsing negative numbers in Sweden, first day of the week in Germany, and probably many other things.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文