3-23 Format3

posted Feb 1, 2014, 9:41 AM by Dlovan ismail   [ updated Feb 1, 2014, 9:41 AM by Karwan Jacksi ]
/*
 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));
       
    } 
}

ċ
Format3.java
(1k)
Karwan Jacksi,
Feb 1, 2014, 9:41 AM
Comments