Export (0) Print
Expand All

Format Class

Visual Studio 2005

An abstract class used as the base class for the rest of the format classes in the java.text package.

Package: java.text

Assembly: vjslib (in vjslib.dll)


public abstract class java.text.Format
    extends java.lang.Object
    implements java.io.Serializable, java.lang.Cloneable

The following example demonstrates the format and parseObject methods of the Format class. This example uses the NumberFormat class, which is a specialization of the abstract Format class.

// format_overview.jsl

import java.math.BigDecimal;
import java.text.*;

public class Program
{
    public static void main(String[] args)
    {
        try
        {
            // Get a default NumberFormat instance.
            NumberFormat numForm = NumberFormat.getInstance();

            // Format some decimals using the pattern supplied above.
            BigDecimal bd1 = new BigDecimal(22.3423D);
            String dest1 = numForm.format(bd1);
            System.out.println("dest1 = " + dest1);

            BigDecimal bd2 = new BigDecimal(64000D);
            String dest2 = numForm.format(bd2);
            System.out.println("dest2 = " + dest2);

            // Parse the decimal string.
            Object o = numForm.parseObject("123456789.14");
            System.out.println("Number = " + o.toString());
        }
        catch (ParseException ex)
        {
            System.out.println(ex.toString());
        }
    }
}

/*
Output:
dest1 = 22.342
dest2 = 64,000
Number = 1.2345678914E8
*/

Community Additions

ADD
Show:
© 2014 Microsoft