/** * Formats a plural message for a given number. * * @param number a number for which the plural message should be formatted. * If no pattern has been applied to this * <code>PluralFormat</code> object yet, the formatted number will * be returned. * @return the string containing the formatted plural message. * @stable ICU 4.0 */ public final String format(double number) { return format(number, number); }
/** * Formats a plural message for a given number and appends the formatted * message to the given <code>StringBuffer</code>. * @param number a number object (instance of <code>Number</code> for which * the plural message should be formatted. If no pattern has been * applied to this <code>PluralFormat</code> object yet, the * formatted number will be returned. * Note: If this object is not an instance of <code>Number</code>, * the <code>toAppendTo</code> will not be modified. * @param toAppendTo the formatted message will be appended to this * <code>StringBuffer</code>. * @param pos will be ignored by this method. * @return the string buffer passed in as toAppendTo, with formatted text * appended. * @throws IllegalArgumentException if number is not an instance of Number * @stable ICU 3.8 */ @Override public StringBuffer format(Object number, StringBuffer toAppendTo, FieldPosition pos) { if (!(number instanceof Number)) { throw new IllegalArgumentException("'" + number + "' is not a Number"); } Number numberObject = (Number) number; toAppendTo.append(format(numberObject, numberObject.doubleValue())); return toAppendTo; }
toInsertInto.insert(pos, ruleText.substring(pluralRuleEnd + 2)); toInsertInto.insert(pos, rulePatternFormat.format(number / power(radix, exponent))); if (pluralRuleStart > 0) { toInsertInto.insert(pos, ruleText.substring(0, pluralRuleStart));
pluralVal = pluralVal / power(radix, exponent); toInsertInto.insert(pos, rulePatternFormat.format((long)(pluralVal))); if (pluralRuleStart > 0) { toInsertInto.insert(pos, ruleText.substring(0, pluralRuleStart));