Decimal Format

Decimal format digunakan untuk membatasi jumlah angka dibelakang koma di dalam pemrograman java.

package latihan.programming;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale;

public class MyNumberFormart {

public static void main(String[] args) {
// TODO Auto-generated method stub

Double nilai = new Double(1234.6);

DecimalFormat ribuan = new DecimalFormat(“###,##0.00”);

System.out.println(“\nNilai (dengan format DecimalFormat(”###,##0.00”)) = ” +ribuan.format(nilai));

}
}

output :

Nilai (dengan format DecimalFormat(”###,##0.00”)) = 1,234.60

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s