3-24 Format4

posted Feb 1, 2014, 9:43 AM by Dlovan ismail   [ updated Feb 1, 2014, 9:43 AM by Karwan Jacksi ]
/*
This program uses the DecimalFormat class to display
formatted numbers in a message dialog.
*/

package format4;
import javax.swing.JOptionPane;
import java.text.DecimalFormat;

public class Format4 
{
    public static void main(String[] args) 
    {
           double number1 = 0.12;
           double number2 = 0.05;

           // Create a DecimalFormat object.
           DecimalFormat formatter = new DecimalFormat("#0%");

          // Display the formatted variable contents.
           JOptionPane.showMessageDialog(null, formatter.format(number1));
           JOptionPane.showMessageDialog(null, formatter.format(number2));
    }   
}

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