Java override locale setting for specific locale

前端 未结 3 1665
野趣味
野趣味 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:45

    Use the applyPattern method:

    final DecimalFormat df = (DecimalFormat)NumberFormat.getCurrencyInstance(locale);
    df.applyPattern("¤#,##0.##");
    
    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-01-18 16:55

    You can construct your own customized format. Have a look at the following link:

    http://docs.oracle.com/javase/tutorial/i18n/format/decimalFormat.html

    0 讨论(0)
提交回复
热议问题