how-to

Conversion between types

How to format currency ?

For base formatting of the currency see this example:

double value = 35.4567;
    
/* get current currency formatter */
    
NumberFormat currency = NumberFormat.getCurrencyInstance();        

/* format to currency */
    
System.out.println( currency.format( value ) );

The output could be:

35,46 Kč

With currency java.text.NumberFormat you can make various changes, for example change currency or set minimal number of fraction places.

double value = 35.4567;
    
/* get current currency formatter */
    
NumberFormat currency = NumberFormat.getCurrencyInstance();        
    
/* set to UK currency */
    
currency.setCurrency( Currency.getInstance( Locale.UK ) );
currency.setMinimumFractionDigits( 3 );
    
/* format to currency */
    
System.out.println( currency.format( value ) );

The output would be:

35,457 GBP