Java Format - Java NumberFormat.format(Object number, StringBuffer toAppendTo, FieldPosition pos)








Syntax

NumberFormat.format(Object number, StringBuffer toAppendTo, FieldPosition pos) has the following syntax.

public StringBuffer format(Object number,   StringBuffer toAppendTo,   FieldPosition pos)

Example

In the following code shows how to use NumberFormat.format(Object number, StringBuffer toAppendTo, FieldPosition pos) method.

/*  w  w  w  .ja  v  a2  s  . c  om*/
import java.text.FieldPosition;
import java.text.NumberFormat;

public class Main {
  public static void main(String[] args) throws Exception {
    NumberFormat numberFormat = NumberFormat.getPercentInstance();
 
    StringBuffer sb = new StringBuffer();
    
    Object value = 111L;
    numberFormat.format(value,sb,new FieldPosition(0));
    System.out.println(sb);
    
  }
}

The code above generates the following result.