Q:

USD Currency Formatting in java?

Below is the Code for the Number Formatter :
double value = 12345.678;
// locale preference should be retrieved from user preferences
Locale defaultLocale = new Locale("en", "US", "USD");
NumberFormat nf = NumberFormat.getCurrencyInstance(defaultLocale);
String formattedValue = nf.format(value);
System.out.println(formattedValue);

The Output Value : $12,345.68
But here ,I would like to have my ouput value as : $12,345.68 USD.
I need to get USD(Currency Code) at the End of the Value.
Also i am Calling Webservice inorder to get the Value ,How do I pass the Value to the Required field ,and Format it?

A:

This code do the tricks : 
    double value = 12345.678;
    java.util.Currency usd = java.util.Currency.getInstance("USD");
    java.text.NumberFormat format = java.text.NumberFormat.getCurrencyInstance(java.util.Locale.US);
    format.setCurrency(usd);
    System.out.println(format.format(value) + " " + usd.getCurrencyCode());

Output : 
$12,345.68 USD

A:

Why can't you just append that value yourself?
System.out.println(formattedValue + " USD");

