Search code examples
javaformatcurrencyjoda-money

NumberFormat vs Joda money


I need to display currency amount with the symbol and format based on currency code. Currently, I'm using a default locale for each currency code since I don't have access to the exact locale along with the currency code and using NumberFormat.format() to get the formatted currency amount with format and symbol. Does Joda money do this all - provide currency code and it displays the formatted currency with symbol? Any help/direction regarding this is appreciated.


Solution

  •  public static void main(String[] args) throws Exception {
    
            Currency usd = java.util.Currency.getInstance("USD");
            NumberFormat format = java.text.NumberFormat.getCurrencyInstance(java.util.Locale.US);
            format.setCurrency(usd);
            System.out.println(format.format(23232312));
        }
    

    Output

    $23,232,312.00