< prev index next >

jdk/src/java.base/share/classes/java/text/NumberFormat.java

Print this page




 255      * The method attempts to parse text starting at the index given by
 256      * <code>pos</code>.
 257      * If parsing succeeds, then the index of <code>pos</code> is updated
 258      * to the index after the last character used (parsing does not necessarily
 259      * use all characters up to the end of the string), and the parsed
 260      * number is returned. The updated <code>pos</code> can be used to
 261      * indicate the starting point for the next call to this method.
 262      * If an error occurs, then the index of <code>pos</code> is not
 263      * changed, the error index of <code>pos</code> is set to the index of
 264      * the character where the error occurred, and null is returned.
 265      * <p>
 266      * See the {@link #parse(String, ParsePosition)} method for more information
 267      * on number parsing.
 268      *
 269      * @param source A <code>String</code>, part of which should be parsed.
 270      * @param pos A <code>ParsePosition</code> object with index and error
 271      *            index information as described above.
 272      * @return A <code>Number</code> parsed from the string. In case of
 273      *         error, returns null.
 274      * @exception NullPointerException if <code>pos</code> is null.

 275      */
 276     @Override
 277     public final Object parseObject(String source, ParsePosition pos) {
 278         return parse(source, pos);
 279     }
 280 
 281    /**
 282      * Specialization of format.
 283      *
 284      * @param number the double number to format
 285      * @return the formatted String
 286      * @exception        ArithmeticException if rounding is needed with rounding
 287      *                   mode being set to RoundingMode.UNNECESSARY
 288      * @see java.text.Format#format
 289      */
 290     public final String format(double number) {
 291         // Use fast-path for double result if that works
 292         String result = fastFormat(number);
 293         if (result != null)
 294             return result;




 255      * The method attempts to parse text starting at the index given by
 256      * <code>pos</code>.
 257      * If parsing succeeds, then the index of <code>pos</code> is updated
 258      * to the index after the last character used (parsing does not necessarily
 259      * use all characters up to the end of the string), and the parsed
 260      * number is returned. The updated <code>pos</code> can be used to
 261      * indicate the starting point for the next call to this method.
 262      * If an error occurs, then the index of <code>pos</code> is not
 263      * changed, the error index of <code>pos</code> is set to the index of
 264      * the character where the error occurred, and null is returned.
 265      * <p>
 266      * See the {@link #parse(String, ParsePosition)} method for more information
 267      * on number parsing.
 268      *
 269      * @param source A <code>String</code>, part of which should be parsed.
 270      * @param pos A <code>ParsePosition</code> object with index and error
 271      *            index information as described above.
 272      * @return A <code>Number</code> parsed from the string. In case of
 273      *         error, returns null.
 274      * @exception NullPointerException if <code>pos</code> is null.
 275      * @throws NullPointerException if {@code source} is null.
 276      */
 277     @Override
 278     public final Object parseObject(String source, ParsePosition pos) {
 279         return parse(source, pos);
 280     }
 281 
 282    /**
 283      * Specialization of format.
 284      *
 285      * @param number the double number to format
 286      * @return the formatted String
 287      * @exception        ArithmeticException if rounding is needed with rounding
 288      *                   mode being set to RoundingMode.UNNECESSARY
 289      * @see java.text.Format#format
 290      */
 291     public final String format(double number) {
 292         // Use fast-path for double result if that works
 293         String result = fastFormat(number);
 294         if (result != null)
 295             return result;


< prev index next >