How do I format a number with leading zeros?

Category: java.text, viewed: 13118 time(s).

This example give you an example using java.text.DecimalFormat class to add leading zeros to a number. For a another method you can read the see the earlier example on How do I add leading zeros to a number?.

package org.kodejava.example.lang;

import java.text.DecimalFormat;
import java.text.NumberFormat;

public class NumberFormatLeadingZerosExample {
    public static void main(String[] args) {
	NumberFormat formatter = new DecimalFormat("0000000");
	String number = formatter.format(2500);
	
	System.out.println("Number with lading zeros: " + number);
    }
}
Click here to lend your support to: Kode Java Org and make a donation at www.pledgie.com !

 

Uncensored Newsgroups
Download Hundreds of Complimentary Industry Resources

Get hundreds of popular Industry magazines, white papers, webinars, podcasts, and more; all available at no cost to you. With more than 600 complimentary offers, you'll find plenty of titles to suit your professional interests and needs. Click Here and Sign up today!

Java Training

Sponsored Links

Our Friends

Statistics

Locations of visitors to this page
visitor stats