Jumat, 28 Januari 2011

Java ( Kode untuk Format desimal )


Kode untuk Format desimal
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale;

/**
 *
 * @author ALI MUHTAS
 */
public class numberformat {
public static void main(String[] args)
{
double money=100550000.75;
NumberFormat formatter1 = new DecimalFormat("Rp###,##0.00");
NumberFormat formatter2 = new DecimalFormat("###,##0.00");
System.out.println(formatter1.format(money));
System.out.println(formatter2.format(money));

NumberFormat formatter3 = NumberFormat.getCurrencyInstance();
NumberFormat formatter4 = NumberFormat.getInstance();
System.out.println(formatter3.format(money));
System.out.println(formatter4.format(money));

DecimalFormat formatter5 = new DecimalFormat("Rp###,##0.00");
DecimalFormat formatter6 = new DecimalFormat("###,##0.00");
System.out.println(formatter5.format(money));
System.out.println(formatter6.format(money));

Double persen = new Double(0.35);
NumberFormat formatter7 = NumberFormat.getPercentInstance();
String data = new String("");
data = formatter7.format(persen);
System.out.println(data);
}
}

0 komentar:

Posting Komentar

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Justin Bieber, Gold Price in India