Wednesday, 25th April 2012
Follow WikiJava on twitter now. @Wikijava

Formatting Numbers in strings

From WikiJava

Jump to: navigation, search


This article shows how easy it is in java to format a number in the preferred way, for example to obtain strings formatted in a standard way.

Contents

the code

import java.text.DecimalFormat;
import java.text.NumberFormat;
 
 
public class NumberFormatter {
 
	/**
	 * @param args
	 */
	public static void main(String[] args) {
 
		for (int i = 0 ; i < 10; i++){
		NumberFormat formatter = new DecimalFormat("000");
		String s = formatter.format(i); 
 
		System.out.println(s);
		}
 
 
	}
 
}


Comments from the users

To be notified via mail on the updates of this discussion you can login and click on watch at the top of the page


Comments on wikijava are disabled now, cause excessive spam.