DecimalFormat Format3() Example
Formats a number and appends the resulting text to the given string buffer.
DecimalFormatclass Format3() method example. This example shows you how to use Format3() method.This method Formats a number and appends the resulting text to the given string buffer.
Here is the code:-
/**
* @Program that Formats a number and appends the resulting text to the given
string buffer.
* Format3.java
* Author:-RoseIndia Team
* Date:-12-Jun-2008
*/
import java.text.*;
public class Format3 {
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 sb = new StringBuffer(24);
StringBuffer str2 = new StringBuffer(24);
FieldPosition pos = new FieldPosition(NumberFormat.FRACTION_FIELD);
//Format a long to produce a string.
sb = d.format(23423L, sb, pos);
//Formats a number and appends the resulting text to the given
//string buffer.
str2 = d.format(new Integer(12), str2.append(sb), pos);
System.out.println("String before Appending :"+sb);
System.out.println("String Produced is= " + str2);
}
} |
Output of the Program
String before Appending :23,423.0
String Produced is= 23,423.012.0
|
|