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.
Example:
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 ) );
Comments & Questions
Add Your Comment