DecimalFormat applyPattern() Example
Apply the given pattern to this Format object.
DecimalFormatclass applyPattern() method example. This example shows you how to use applyPattern() method.This method Apply the given pattern to this Format object.
Here is the code:-
/**
* @Program that Apply the given pattern to this Format object.
* ApplyPattern.java
* Author:-RoseIndia Team
* Date:-12-Jun-2008
*/
import java.text.*;
public class ApplyPattern {
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);
str = d.format(22.3423D, str, pos);
System.out.println("String Produced is= " + str);
}
} |
Output of the Program
| String Produced is= 22.34 |
|