This documentation is archived and is not being maintained.

NumberFormat.parse Method (String)

Visual Studio 2005

Parses a string into a number represented by a Number object.

Package: java.text

Assembly: vjslib (in vjslib.dll)


public java.lang.Number parse(
    java.lang.String sourceStr) throws java.text.ParseException;

Parameters

sourceStr

The string to be parsed into a number represented by a Number object.

A Number object containing the number parsed from the string.

The following example shows how to create a Number object using a string representation of a decimal.

// numberformat_parse.jsl

import java.text.*;

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

            // Parse a decimal value.
            Number n = numForm.parse("123456789.14");
            System.out.println("Number = " + n);
        }
        catch (ParseException ex)
        {
            System.out.println(ex.toString());
        }
    }
}

/*
Output:
Number = 1.2345678914E8
*/
Show: