/** * Converts an object to an instance of {@link Number} using the * specified format and the {@link Locale} returned by * {@link #getLocale()} if the object is not already an instance * of Number. * * @param format - the format the number is in * @param obj - the number to convert * @return the object as a {@link Number} or <code>null</code> if no * conversion is possible * @see #toNumber(String format, Object obj, Locale locale) */ public Number toNumber(String format, Object obj) { return toNumber(format, obj, getLocale()); }
/** * Converts the specified object to a number and returns * a formatted string representing that number in the specified * {@link Locale}. * * @param format the custom or standard pattern to be used * @param obj the number object to be formatted * @param locale the {@link Locale} to be used when formatting * @return a formatted string representing the specified number or * <code>null</code> if the parameters are invalid */ public String format(String format, Object obj, Locale locale) { Number number = toNumber(obj); NumberFormat nf = getNumberFormat(format, locale); if (number == null || nf == null) { return null; } return nf.format(number); }
/** * Converts an object to an instance of {@link Number} using the * format returned by {@link #getFormat()} and the {@link Locale} * returned by {@link #getLocale()} if the object is not already * an instance of Number. * * @param obj the number to convert * @return the object as a {@link Number} or <code>null</code> if no * conversion is possible */ public Number toNumber(Object obj) { return toNumber(getFormat(), obj, getLocale()); }