The Answer to Life, the Universe, and Everything

Showing posts with label decimal. Show all posts
Showing posts with label decimal. Show all posts

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