The Answer to Life, the Universe, and Everything

Monday, August 13, 2007

Formats decimal numbers by Java

DecimalFormat df = new DecimalFormat("0000");
df.format(77);
#OUTPUT: 0077


DecimalFormat df = new DecimalFormat("####");
df.format(77);
#OUTPUT: 77


DecimalFormat df = new DecimalFormat("####%");
df.format(77);
#OUTPUT: 77%


DecimalFormat df = new DecimalFormat("'AA'####%");
df.format(77);
#OUTPUT: AA77%


DecimalFormat df = new DecimalFormat("\u00A5###,###");
df.format(7777);
#OUTPUT: \7,777

1 comment:

Channon said...

Good for people to know.