Codessentials

  • Increase font size
  • Default font size
  • Decrease font size
Home Coding tips Java How to add leading zeros

How to add leading zeros

Here is a snippit to print a number 1125 as 1,125:

Integer nr = 1125;
DecimalFormat myFormatter = new DecimalFormat("#,###");
String strNr = myFormatter.format(Integer);
System.out.println(strNr);

More information about formatting can be found here:

http://java.sun.com/docs/books/tutorial/i18n/format/decimalFormat.html


 

Bookmark

AddThis Social Bookmark Button

Related Articles


Newsflash

Jack Wallen is the host of the TechRepublic open source blog as well as a regular writer in the "10 Things..." and the "How Do I..." blogs.

In this article Jack Wallen reviews Yadis! Backup.

Some highlights:

There are tons of backup solutions available, ranging from simple, single-user applications to much larger, complex solutions. Most all of these solutions will do what the creators claim — back up your data. You always hope that data is backed up safely and that it will be there in that unforeseen moment when you need it. There is one backup solution amid the myriad of others that offers a unique little twist on the old tried-and-true process. Yadis! Backup.
...

Yadis! Backup is one of the more foolproof backup solutions I’ve come across. If you are looking for a simple backup solution that does not require any scheduling, this might be what you are seeking. It’s not exactly Enterprise-ready, but for smaller backups it’s a pretty sweet solution.

Read the full article here.