Java Code Snippet: Converting a Float or Decimal to Currency Formatted String

Java provides multiple Text Formatting classes to enable easy conversion of integers, decimals, floats, and etc into Strings. The DecimalFormat class enables the formatting of Floats and Decimals and can be used to easily display percentages and currency amounts.


Converting a Float into Dollars formatted String

import java.text.DecimalFormat;
float amount = 100453.23f;
DecimalFormat dollarFormat = new DecimalFormat( "$#,##0.0#" );
System.out.println( dollarFormat.format( amount ) );


// Code Snippets // Java //

Comments & Questions

Add Your Comment