Java DecimalFormat .applyPattern (String pattern)

Syntax

DecimalFormat.applyPattern(String pattern) has the following syntax.

public void applyPattern(String pattern)

Example

In the following code shows how to use DecimalFormat.applyPattern(String pattern) method.


import java.text.DecimalFormat;
/*w w  w .j a va  2 s.  c  om*/
public class Main {
  public static void main(String[] argv) throws Exception {
    DecimalFormat format = new DecimalFormat();
    format.applyPattern("##.##");
    System.out.println(format.format(-123456789.12345678));

  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.text »




DateFormat
DecimalFormat
NumberFormat
SimpleDateFormat