3-23 Format3
Post date: Feb 1, 2014 5:41:20 PM
/*
This program uses the DecimalFormat class to display
formatted numbers in a message dialog.
*/
package format3;
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class Format3
{
public static void main(String[] args)
{
double number1 = 123.899;
double number2 = 1233.899;
double number3 = 12345.899;
double number4 = 123456.899;
double number5 = 1234567.899;
// Create a DecimalFormat object.
DecimalFormat formatter = new DecimalFormat("#,##0.00");
// Diiplay the formatted variable contents.
JOptionPane.showMessageDialog(null,formatter.format(number1));
JOptionPane.showMessageDialog(null,formatter.format(number2));
JOptionPane.showMessageDialog(null,formatter.format(number3));
JOptionPane.showMessageDialog(null,formatter.format(number4));
JOptionPane.showMessageDialog(null,formatter.format(number5));
}
}