Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Decimal Alignment

 
Timothy Leong
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,
I have the following numbers

1.2 5.6
62.4 87.2

how do i align to become

1.2 5.6
62.4 87.2

soo tt the decimal symbols are aligned?
thanks
 
Timothy Leong
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think my additional spaces get removed

should be like this

#1.2 #5.6
62.4 87.2

thanks
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use java.text.DecimalFormat to format them. In Java 5, you could also use the new Formatter capability; see System.out.printf().
 
Manuel Moons
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using the # will indeed leave out 0.

The format you want to use is something like this #0.00

Look at the explanation of the pattern in the javadoc

DecimalFormat javadoc
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic