RTL语言环境中的负数数字问题像阿拉伯语一样
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)解析负数?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从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.