Java printf format of 10 useful examples

preview_player
Показать описание

public class Ch11Format {

public static void main(String[] args) {
double price = 1.2159;
double salary = 1055000.55;
// output to 1.22
// output to 1.216
// total 10 spaces, 2 numbers after decimal point
// include price: 6 spaces, 2 numbers after decimal pont
// left aligment the price
// total 10 spaces, 2 decmal numbers, leading 0
// 2 decimal numbers, thousand separator
// create your own format 2 decimal numbers, thousand separator
DecimalFormat myFormat = new DecimalFormat("$###,###.##");
// display today's date

String pattern = "yyyy-MM-dd";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
// display the salary £, Chinese ¥
DecimalFormat myFormat1 = new DecimalFormat("\u00A5###,###.##");



}
Рекомендации по теме