数字国际化 (I18N with Number)

2025 年 3 月 17 日 | 阅读 1 分钟

数字的表示方式因地区而异。 对于根据区域设置显示信息的应用程序来说,对数字进行国际化是一个好方法。

NumberFormat 类用于根据特定区域设置格式化数字。 要获取 NumberFormat 类的实例,我们需要调用 getInstance()getNumberInstance() 方法。

这些方法的语法如下


数字国际化示例

在本示例中,我们对数字进行国际化。 NumberFormat 类的 format 方法将双精度值格式化为特定于区域设置的数字。

Output:105,500.324 for the locale en_GB
       105,000.324 for the locale en_US
       105,a000,324 for the locale fr_FR
       105,000.324 for the locale ja_JP

下一主题货币国际化