DecimalFormat Format2() Example
Format a long to produce a string.
DecimalFormatclass Format2() method example. This example shows you how to use Format2() method.This method Format a long to produce a string.
Here is the code:-
/**
* @Program that Format a long to produce a string.
* Format2.java
* Author:-RoseIndia Team
* Date:-12-Jun-2008
*/
import java.text.*;
public class Format2 {
public static void main(String[] args) {
// Creates a DecimalFormat object
DecimalFormat d = new DecimalFormat();
//Apply the given pattern to this Format object.
d.applyPattern("#,#00.0#");
// Format decimals using the pattern supplied above.
StringBuffer str = new StringBuffer(24);
FieldPosition pos = new FieldPosition(NumberFormat.FRACTION_FIELD);
//Format a long to produce a string.
str = d.format(223423L, str, pos);
System.out.println("String Produced is= " + str);
}
} |
Output of the Program
| String Produced is= 223,423.0 |
|