Logo Search packages:      
Sourcecode: icu version File versions  Download package

UnicodeString & NumberFormat::format ( const Formattable obj,
UnicodeString appendTo,
FieldPosition pos,
UErrorCode status 
) const [virtual]

Format an object to produce a string. This method handles Formattable objects with numeric types. If the Formattable object type is not a numeric type, then it returns a failing UErrorCode.

obj The object to format.
appendTo Output parameter to receive result. Result is appended to existing contents.
pos On input: an alignment field, if desired. On output: the offsets of the alignment field.
status Output param filled with success/failure status.
Reference to 'appendTo' parameter. ICU 2.0

Implements Format.

Reimplemented in ChoiceFormat, DecimalFormat, and RuleBasedNumberFormat.

Definition at line 438 of file numfmt.cpp.

References Formattable::getDigitList(), Formattable::getDouble(), Formattable::getInt64(), Formattable::getLong(), Formattable::getType(), Formattable::isNumeric(), Formattable::kDouble, Formattable::kInt64, Formattable::kLong, NULL, U_FAILURE, and U_INVALID_FORMAT_ERROR.

Referenced by RuleBasedNumberFormat::format(), PluralFormat::format(), format(), DecimalFormat::format(), CurrencyFormat::format(), ChoiceFormat::format(), SimpleDateFormat::subFormat(), LocaleTest::Test4105828(), NumberFormatRegressionTest::Test4161100(), NumberFormatRegressionTest::Test4162198(), NumberFormatRegressionTest::Test4162852(), NumberFormatRegressionTest::Test4167494(), NumberFormatRegressionTest::Test4217661(), NumberFormatTest::TestAPI(), IntlTestNumberFormatAPI::testAPI(), NumberFormatTest::TestCurrency(), LocaleTest::TestEuroSupport(), NumberFormatTest::TestSecondaryGrouping(), IntlTestNumberFormat::tryIt(), and SimpleDateFormat::zeroPaddingNumber().

    if (U_FAILURE(status)) return appendTo;

    ArgExtractor arg(*this, obj, status);
    const Formattable *n = arg.number();

    if (n->isNumeric() && n->getDigitList() != NULL) {
        // Decimal Number.  We will have a DigitList available if the value was
        //   set to a decimal number, or if the value originated with a parse.
        // The default implementation for formatting a DigitList converts it
        // to a double, and formats that, allowing formatting classes that don't
        // know about DigitList to continue to operate as they had.
        // DecimalFormat overrides the DigitList formatting functions.
        format(*n->getDigitList(), appendTo, pos, status);
    } else {
        switch (n->getType()) {
        case Formattable::kDouble:
            format(n->getDouble(), appendTo, pos);
        case Formattable::kLong:
            format(n->getLong(), appendTo, pos);
        case Formattable::kInt64:
            format(n->getInt64(), appendTo, pos);
            status = U_INVALID_FORMAT_ERROR;

    return appendTo;

Generated by  Doxygen 1.6.0   Back to index