The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
August 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

RE: Number Format

Posted by Kishori Sharan on August 10, 2000 at 1:43 PM

Hi
Here is a small example for what you want. You can explore java.text package for more info.

Thanx
Kishori
////////// Example

import java.text.* ;
class NumFormat {
public static void main ( String[] args ) {

NumberFormat nf = NumberFormat.getNumberInstance ( );
nf.setMinimumIntegerDigits ( 4 ) ;
nf.setGroupingUsed ( false ) ; //if you don't want comma
// as thousand separator
System.out.println ( nf.format ( 1 ) );
System.out.println ( nf.format ( 23 ) );
System.out.println ( nf.format ( 100 ) );
System.out.println ( nf.format ( 1278 ) );
}

}



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us