Here you can find the source of toNumber(String numString, String numFormatPattern)
Parameter | Description |
---|---|
numString | the String to convert |
numFormatPattern | the pattern |
public static Number toNumber(String numString, String numFormatPattern) throws ParseException
//package com.java2s; /**// w w w .ja va 2 s . co m * Copyright (C) 2002-2005 WUZEWEN. All rights reserved. * WUZEWEN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ import java.text.DecimalFormat; import java.text.ParseException; public class Main { private static DecimalFormat numberFormat = new DecimalFormat(); /** * Converts a String to a Number, using the specified pattern. * (see java.text.NumberFormat for pattern description) * * @param numString the String to convert * @param numFormatPattern the pattern * @return the corresponding Number * @exception ParseException, if the String doesn't match the pattern */ public static Number toNumber(String numString, String numFormatPattern) throws ParseException { Number number = null; if (numFormatPattern == null) { numFormatPattern = "######.##"; } synchronized (numberFormat) { numberFormat.applyPattern(numFormatPattern); number = numberFormat.parse(numString); } return number; } }