Java override locale setting for specific locale

前端 未结 3 1667
野趣味
野趣味 2021-01-18 16:36

I\'m using NumberFormat.getCurrencyInstance().format(amount) to format currency from a BigDecimal to a string. This works as expected the problem is that our ma

3条回答
  •  孤街浪徒
    2021-01-18 16:47

    Leaving aside the question of whether that particular format is "correct" or not, the way to change the currency instance for the "nl" locale is to implement and configure a custom LocaleServiceProvider for the number format service. (The provider class needs to subclass NumberFormatProvider, but the superclass javadoc explains how to configure the provider.)

    The provider needs to return a non-standard NumberFormat instance for the particular case you are concerned about, but (presumably) delegate to the default provider in other cases.

提交回复
热议问题