Movatterモバイル変換


[0]ホーム

URL:


ICU 78.1  78.1
Public Types |Public Member Functions |Static Public Member Functions |Protected Member Functions |Static Protected Member Functions |Static Protected Attributes |Friends
icu::NumberFormat Class Referenceabstract

#include "unicode/numfmt.h"

Inheritance diagram for icu::NumberFormat:

Public Types

enum  ERoundingMode {
  kRoundCeiling,kRoundFloor,kRoundDown,kRoundUp,
  kRoundHalfEven,kRoundHalfDown,kRoundHalfUp,kRoundUnnecessary,
  kRoundHalfOdd,kRoundHalfCeiling,kRoundHalfFloor
}
 Rounding mode.More...
 
enum  EAlignmentFields {
  kIntegerField = UNUM_INTEGER_FIELD,kFractionField = UNUM_FRACTION_FIELD,kDecimalSeparatorField = UNUM_DECIMAL_SEPARATOR_FIELD,kExponentSymbolField = UNUM_EXPONENT_SYMBOL_FIELD,
  kExponentSignField = UNUM_EXPONENT_SIGN_FIELD,kExponentField = UNUM_EXPONENT_FIELD,kGroupingSeparatorField = UNUM_GROUPING_SEPARATOR_FIELD,kCurrencyField = UNUM_CURRENCY_FIELD,
  kPercentField = UNUM_PERCENT_FIELD,kPermillField = UNUM_PERMILL_FIELD,kSignField = UNUM_SIGN_FIELD,kMeasureUnitField = UNUM_MEASURE_UNIT_FIELD,
  kCompactField = UNUM_COMPACT_FIELD,INTEGER_FIELD = UNUM_INTEGER_FIELD,FRACTION_FIELD = UNUM_FRACTION_FIELD
}
 Alignment Field constants used to construct aFieldPosition object.More...
 

Public Member Functions

virtual ~NumberFormat ()
 Destructor.More...
 
virtualNumberFormatclone () const override=0
 Clones this object polymorphically.More...
 
virtual bool operator== (constFormat &other) const override
 Return true if the givenFormat objects are semantically equal.More...
 
virtualUnicodeStringformat (constFormattable &obj,UnicodeString &appendTo,FieldPosition &pos,UErrorCode &status) const override
 Format an object to produce a string.More...
 
virtualUnicodeStringformat (constFormattable &obj,UnicodeString &appendTo,FieldPositionIterator *posIter,UErrorCode &status) const override
 Format an object to produce a string.More...
 
virtual void parseObject (constUnicodeString &source,Formattable &result,ParsePosition &parse_pos) const override
 Parse a string to produce an object.More...
 
UnicodeStringformat (double number,UnicodeString &appendTo) const
 Format a double number.More...
 
UnicodeStringformat (int32_t number,UnicodeString &appendTo) const
 Format a long number.More...
 
UnicodeStringformat (int64_t number,UnicodeString &appendTo) const
 Format an int64 number.More...
 
virtualUnicodeStringformat (double number,UnicodeString &appendTo,FieldPosition &pos) const =0
 Format a double number.More...
 
virtualUnicodeStringformat (double number,UnicodeString &appendTo,FieldPosition &pos,UErrorCode &status) const
 Format a double number.More...
 
virtualUnicodeStringformat (double number,UnicodeString &appendTo,FieldPositionIterator *posIter,UErrorCode &status) const
 Format a double number.More...
 
virtualUnicodeStringformat (int32_t number,UnicodeString &appendTo,FieldPosition &pos) const =0
 Format a long number.More...
 
virtualUnicodeStringformat (int32_t number,UnicodeString &appendTo,FieldPosition &pos,UErrorCode &status) const
 Format a long number.More...
 
virtualUnicodeStringformat (int32_t number,UnicodeString &appendTo,FieldPositionIterator *posIter,UErrorCode &status) const
 Format an int32 number.More...
 
virtualUnicodeStringformat (int64_t number,UnicodeString &appendTo,FieldPosition &pos) const
 Format an int64 number.More...
 
virtualUnicodeStringformat (int64_t number,UnicodeString &appendTo,FieldPosition &pos,UErrorCode &status) const
 Format an int64 number.More...
 
virtualUnicodeStringformat (int64_t number,UnicodeString &appendTo,FieldPositionIterator *posIter,UErrorCode &status) const
 Format an int64 number.More...
 
virtualUnicodeStringformat (StringPiece number,UnicodeString &appendTo,FieldPositionIterator *posIter,UErrorCode &status) const
 Format a decimal number.More...
 
virtualUnicodeStringformat (const number::impl::DecimalQuantity &number,UnicodeString &appendTo,FieldPositionIterator *posIter,UErrorCode &status) const
 Format a decimal number.More...
 
virtualUnicodeStringformat (const number::impl::DecimalQuantity &number,UnicodeString &appendTo,FieldPosition &pos,UErrorCode &status) const
 Format a decimal number.More...
 
virtual void parse (constUnicodeString &text,Formattable &result,ParsePosition &parsePosition) const =0
 Return a long if possible (e.g.More...
 
virtual void parse (constUnicodeString &text,Formattable &result,UErrorCode &status) const
 Parse a string as a numeric value, and return aFormattable numeric object.More...
 
virtualCurrencyAmountparseCurrency (constUnicodeString &text,ParsePosition &pos) const
 Parses text from the given string as a currency amount.More...
 
UBool isParseIntegerOnly () const
 Return true if this format will parse numbers as integers only.More...
 
virtual void setParseIntegerOnly (UBool value)
 Sets whether or not numbers should be parsed as integers only.More...
 
virtual void setLenient (UBool enable)
 Sets whether lenient parsing should be enabled (it is off by default).More...
 
virtualUBool isLenient () const
 Returns whether lenient parsing is enabled (it is off by default).More...
 
UBool isGroupingUsed () const
 Returns true if grouping is used in this format.More...
 
virtual void setGroupingUsed (UBool newValue)
 Set whether or not grouping will be used in this format.More...
 
int32_t getMaximumIntegerDigits () const
 Returns the maximum number of digits allowed in the integer portion of a number.More...
 
virtual void setMaximumIntegerDigits (int32_t newValue)
 Sets the maximum number of digits allowed in the integer portion of a number.More...
 
int32_t getMinimumIntegerDigits () const
 Returns the minimum number of digits allowed in the integer portion of a number.More...
 
virtual void setMinimumIntegerDigits (int32_t newValue)
 Sets the minimum number of digits allowed in the integer portion of a number.More...
 
int32_t getMaximumFractionDigits () const
 Returns the maximum number of digits allowed in the fraction portion of a number.More...
 
virtual void setMaximumFractionDigits (int32_t newValue)
 Sets the maximum number of digits allowed in the fraction portion of a number.More...
 
int32_t getMinimumFractionDigits () const
 Returns the minimum number of digits allowed in the fraction portion of a number.More...
 
virtual void setMinimumFractionDigits (int32_t newValue)
 Sets the minimum number of digits allowed in the fraction portion of a number.More...
 
virtual void setCurrency (const char16_t *theCurrency,UErrorCode &ec)
 Sets the currency used to display currency amounts.More...
 
const char16_t * getCurrency () const
 Gets the currency used to display currency amounts.More...
 
virtual void setContext (UDisplayContext value,UErrorCode &status)
 Set a particular UDisplayContext value in the formatter, such as UDISPCTX_CAPITALIZATION_FOR_STANDALONE.More...
 
virtualUDisplayContext getContext (UDisplayContextType type,UErrorCode &status) const
 Get the formatter's UDisplayContext value for the specified UDisplayContextType, such as UDISPCTX_TYPE_CAPITALIZATION.More...
 
virtualERoundingMode getRoundingMode () const
 Get the rounding mode.More...
 
virtual void setRoundingMode (ERoundingMode roundingMode)
 Set the rounding mode.More...
 
virtualUClassID getDynamicClassID () const override=0
 Returns a unique class ID POLYMORPHICALLY.More...
 
U_I18N_APIUnicodeStringformat (constFormattable &obj,UnicodeString &appendTo,UErrorCode &status) const
 Formats an object to produce a string.More...
 
virtualU_I18N_APIUnicodeStringformat (constFormattable &obj,UnicodeString &appendTo,FieldPosition &pos,UErrorCode &status) const=0
 Format an object to produce a string.More...
 
virtualU_I18N_APIUnicodeStringformat (constFormattable &obj,UnicodeString &appendTo,FieldPositionIterator *posIter,UErrorCode &status) const
 Format an object to produce a string.More...
 
- Public Member Functions inherited fromicu::Format
virtualU_I18N_API ~Format ()
 Destructor.More...
 
U_I18N_API bool operator!= (constFormat &other) const
 Return true if the givenFormat objects are not semantically equal.More...
 
U_I18N_APIUnicodeStringformat (constFormattable &obj,UnicodeString &appendTo,UErrorCode &status) const
 Formats an object to produce a string.More...
 
U_I18N_API void parseObject (constUnicodeString &source,Formattable &result,UErrorCode &status) const
 Parses a string to produce an object.More...
 
U_I18N_APILocale getLocale (ULocDataLocaleType type,UErrorCode &status) const
 Get the locale for this format object.More...
 
U_I18N_API const char * getLocaleID (ULocDataLocaleType type,UErrorCode &status) const
 Get the locale for this format object.More...
 
- Public Member Functions inherited fromicu::UObject
virtual ~UObject ()
 Destructor.More...
 

Static Public Member Functions

staticNumberFormatcreateInstance (UErrorCode &)
 Create a default styleNumberFormat for the current default locale.More...
 
staticNumberFormatcreateInstance (constLocale &inLocale,UErrorCode &)
 Create a default styleNumberFormat for the specified locale.More...
 
staticNumberFormatcreateInstance (constLocale &desiredLocale,UNumberFormatStyle style,UErrorCode &errorCode)
 Create a specific styleNumberFormat for the specified locale.More...
 
staticNumberFormatinternalCreateInstance (constLocale &desiredLocale,UNumberFormatStyle style,UErrorCode &errorCode)
 ICU use only.More...
 
static const SharedNumberFormat * createSharedInstance (constLocale &inLocale,UNumberFormatStyle style,UErrorCode &status)
 ICU use only.More...
 
staticNumberFormatcreateCurrencyInstance (UErrorCode &)
 Returns a currency format for the current default locale.More...
 
staticNumberFormatcreateCurrencyInstance (constLocale &inLocale,UErrorCode &)
 Returns a currency format for the specified locale.More...
 
staticNumberFormatcreatePercentInstance (UErrorCode &)
 Returns a percentage format for the current default locale.More...
 
staticNumberFormatcreatePercentInstance (constLocale &inLocale,UErrorCode &)
 Returns a percentage format for the specified locale.More...
 
staticNumberFormatcreateScientificInstance (UErrorCode &)
 Returns a scientific format for the current default locale.More...
 
staticNumberFormatcreateScientificInstance (constLocale &inLocale,UErrorCode &)
 Returns a scientific format for the specified locale.More...
 
static constLocalegetAvailableLocales (int32_t &count)
 Get the set of Locales for which NumberFormats are installed.More...
 
staticURegistryKey registerFactory (NumberFormatFactory *toAdopt,UErrorCode &status)
 Register a newNumberFormatFactory.More...
 
staticUBool unregister (URegistryKey key,UErrorCode &status)
 Unregister a previously-registeredNumberFormatFactory using the key returned from the register call.More...
 
staticStringEnumerationgetAvailableLocales ()
 Return aStringEnumeration over the locales available at the time of the call, including registered locales.More...
 
staticUClassID getStaticClassID ()
 Return the class ID for this class.More...
 

Protected Member Functions

 NumberFormat ()
 Default constructor for subclass use only.More...
 
 NumberFormat (constNumberFormat &)
 Copy constructor.More...
 
NumberFormatoperator= (constNumberFormat &)
 Assignment operator.More...
 
virtual void getEffectiveCurrency (char16_t *result,UErrorCode &ec) const
 Returns the currency in effect for this formatter.More...
 
- Protected Member Functions inherited fromicu::Format
U_I18N_API void setLocaleIDs (const char *valid, const char *actual)
 
U_I18N_API Format ()
 Default constructor for subclass use only.More...
 
U_I18N_API Format (constFormat &)
 
U_I18N_APIFormatoperator= (constFormat &)
 

Static Protected Member Functions

staticNumberFormatmakeInstance (constLocale &desiredLocale,UNumberFormatStyle style,UBool mustBeDecimalFormat,UErrorCode &errorCode)
 Creates the specified number format style of the desired locale.More...
 
- Static Protected Member Functions inherited fromicu::Format
staticU_I18N_API void syntaxError (constUnicodeString &pattern, int32_t pos,UParseError &parseError)
 Simple function for initializing aUParseError from aUnicodeString.More...
 

Static Protected Attributes

static const int32_t gDefaultMaxIntegerDigits
 
static const int32_t gDefaultMinIntegerDigits
 

Friends

class ICUNumberFormatFactory
 
class ICUNumberFormatService
 
class ::NumberFormatTest
 

Detailed Description

IMPORTANT: New users are strongly encouraged to see ifnumberformatter.h fits their use case. Although not deprecated, this header is provided for backwards compatibility only.

Abstract base class for all number formats. Provides interface for formatting and parsing a number. Also provides methods for determining which locales have number formats, and what their names are.

NumberFormat helps you to format and parse numbers for any locale. Your code can be completely independent of the locale conventions for decimal points, thousands-separators, or even the particular decimal digits used, or whether the number format is even decimal.

To format a number for the currentLocale, use one of the static factory methods:

#include <iostream>
#include "unicode/numfmt.h"
#include "unicode/unistr.h"
#include "unicode/ustream.h"
using namespacestd;
int main() {
double myNumber = 7.0;
UnicodeString myString;
UErrorCode success =U_ZERO_ERROR;
NumberFormat* nf =NumberFormat::createInstance(success);
nf->format(myNumber, myString);
cout <<" Example 1: " << myString << endl;
}
icu::NumberFormat::createInstance
static NumberFormat * createInstance(UErrorCode &)
Create a default style NumberFormat for the current default locale.
icu::NumberFormat::NumberFormat
NumberFormat()
Default constructor for subclass use only.
numfmt.h
C++ API: Compatibility APIs for number formatting.
unistr.h
C++ API: Unicode String.
ustream.h
C++ API: Unicode iostream like API.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition:utypes.h:509
U_ZERO_ERROR
@ U_ZERO_ERROR
No error, no warning.
Definition:utypes.h:544

Note that there are additional factory methods within subclasses ofNumberFormat.

If you are formatting multiple numbers, it is more efficient to get the format and use it multiple times so that the system doesn't have to fetch the information about the local language and country conventions multiple times.

UnicodeString myString;
UErrorCode success =U_ZERO_ERROR;
NumberFormat *nf =NumberFormat::createInstance( success );
for (int32_t number: {123, 3333, -1234567}) {
nf->format(number, myString);
myString +="; ";
}
cout <<" Example 2: " << myString << endl;

To format a number for a differentLocale, specify it in the call tocreateInstance().

nf =NumberFormat::createInstance(Locale::getFrench(), success);
icu::Locale::getFrench
static U_COMMON_API const Locale & getFrench()
Useful constant for this language.

You can use aNumberFormat to parse also.

UErrorCode success;
Formattable result(-999);// initialized with error code
nf->parse(myString, result, success);

UsecreateInstance() to get the normal number format for aLocale. There are other static factory methods available. UsecreateCurrencyInstance() to get the currency number format for that country. UsecreatePercentInstance() to get a format for displaying percentages. With this format, a fraction from 0.53 is displayed as 53%.

The type of number formatting can be specified by passing a 'style' parameter tocreateInstance(). For example, use
createInstance(locale, UNUM_DECIMAL, errorCode) to get the normal number format,
createInstance(locale, UNUM_PERCENT, errorCode) to get a format for displaying percentage,
createInstance(locale, UNUM_SCIENTIFIC, errorCode) to get a format for displaying scientific number,
createInstance(locale, UNUM_CURRENCY, errorCode) to get the currency number format, in which the currency is represented by its symbol, for example, "$3.00".
createInstance(locale, UNUM_CURRENCY_ISO, errorCode) to get the currency number format, in which the currency is represented by its ISO code, for example "USD3.00".
createInstance(locale, UNUM_CURRENCY_PLURAL, errorCode) to get the currency number format, in which the currency is represented by its full name in plural format, for example, "3.00 US dollars" or "1.00 US dollar".

You can also control the display of numbers with such methods asgetMinimumFractionDigits(). If you want even more control over the format or parsing, or want to give your users more control, you can try dynamic_casting theNumberFormat you get from the factory methods to aDecimalFormat. This will work for the vast majority of countries; just remember to test for nullptr in case you encounter an unusual one.

You can also use forms of the parse and format methods withParsePosition andFieldPosition to allow you to:

For example, you can align numbers in two ways.

If you are using a monospaced font with spacing for alignment, you can pass theFieldPosition in your format call, with field =UNUM_INTEGER_FIELD. On output,getEndIndex will be set to the offset between the last character of the integer and the decimal. Add (desiredSpaceCount - getEndIndex) spaces at the front of the string.

If you are using proportional fonts, instead of padding with spaces, measure the width of the string in pixels from the start to getEndIndex. Then move the pen by (desiredPixelWidth - widthToAlignmentPoint) before drawing the text. It also works where there is no decimal, but possibly additional characters at the end, e.g. with parentheses in negative numbers: "(12)" for -12.

User subclasses are not supported. While clients may write subclasses, such code will not necessarily work and will not be guaranteed to work stably from release to release.

Stable:
ICU 2.0

Definition at line175 of filenumfmt.h.

Member Enumeration Documentation

◆ EAlignmentFields

enumicu::NumberFormat::EAlignmentFields

Alignment Field constants used to construct aFieldPosition object.

Signifies that the position of the integer part or fraction part of a formatted number should be returned.

Note: as of ICU 4.4, the values in this enum have been extended to support identification of all number format fields, not just those pertaining to alignment.

These constants are provided for backwards compatibility only. Please use the C style constants defined in the header fileunum.h.

See also
FieldPosition
Stable:
ICU 2.0
Enumerator
kIntegerField 
Stable:
ICU 2.0
kFractionField 
Stable:
ICU 2.0
kDecimalSeparatorField 
Stable:
ICU 2.0
kExponentSymbolField 
Stable:
ICU 2.0
kExponentSignField 
Stable:
ICU 2.0
kExponentField 
Stable:
ICU 2.0
kGroupingSeparatorField 
Stable:
ICU 2.0
kCurrencyField 
Stable:
ICU 2.0
kPercentField 
Stable:
ICU 2.0
kPermillField 
Stable:
ICU 2.0
kSignField 
Stable:
ICU 2.0
kMeasureUnitField 
Stable:
ICU 64
kCompactField 
Stable:
ICU 64
INTEGER_FIELD 

These constants are provided for backwards compatibility only.

Please use the constants defined in the header fileunum.h.

Stable:
ICU 2.0
FRACTION_FIELD 
Stable:
ICU 2.0

Definition at line234 of filenumfmt.h.

◆ ERoundingMode

enumicu::NumberFormat::ERoundingMode

Rounding mode.

For more detail on rounding modes, see:https://unicode-org.github.io/icu/userguide/format_parse/numbers/rounding-modes

Stable:
ICU 2.4
Enumerator
kRoundCeiling 

Round towards positive infinity.

kRoundFloor 

Round towards negative infinity.

kRoundDown 

Round towards zero.

kRoundUp 

Round away from zero.

kRoundHalfEven 

Round towards the nearest integer, or towards the nearest even integer if equidistant.

kRoundHalfDown 

Round towards the nearest integer, or towards zero if equidistant.

kRoundHalfUp 

Round towards the nearest integer, or away from zero if equidistant.

kRoundUnnecessary 

Return U_FORMAT_INEXACT_ERROR if number does not format exactly.

Stable:
ICU 4.8
kRoundHalfOdd 

Rounds ties toward the odd number.

Stable:
ICU 73
kRoundHalfCeiling 

Rounds ties toward +∞.

Stable:
ICU 73
kRoundHalfFloor 

Rounds ties toward -∞.

Stable:
ICU 73

Definition at line186 of filenumfmt.h.

Constructor & Destructor Documentation

◆ ~NumberFormat()

virtual icu::NumberFormat::~NumberFormat()
virtual

Destructor.

Stable:
ICU 2.0

◆ NumberFormat()[1/2]

icu::NumberFormat::NumberFormat()
protected

Default constructor for subclass use only.

Stable:
ICU 2.0

◆ NumberFormat()[2/2]

icu::NumberFormat::NumberFormat(constNumberFormat)
protected

Copy constructor.

Stable:
ICU 2.0

Member Function Documentation

◆ clone()

virtualNumberFormat* icu::NumberFormat::clone() const
overridepure virtual

Clones this object polymorphically.

The caller owns the result and should delete it when done.

Returns
clone, or nullptr if an error occurred
Stable:
ICU 2.0

Implementsicu::Format.

Implemented inicu::RuleBasedNumberFormat,icu::DecimalFormat,icu::CompactDecimalFormat, andicu::ChoiceFormat.

◆ createCurrencyInstance()[1/2]

staticNumberFormat* icu::NumberFormat::createCurrencyInstance(constLocaleinLocale,
UErrorCode 
)
static

Returns a currency format for the specified locale.

NOTE: New users are strongly encouraged to useicu::number::NumberFormatter instead ofNumberFormat.

Parameters
inLocalethe given locale.
Stable:
ICU 2.0

◆ createCurrencyInstance()[2/2]

staticNumberFormat* icu::NumberFormat::createCurrencyInstance(UErrorCode)
static

Returns a currency format for the current default locale.

NOTE: New users are strongly encouraged to useicu::number::NumberFormatter instead ofNumberFormat.

Stable:
ICU 2.0

◆ createInstance()[1/3]

staticNumberFormat* icu::NumberFormat::createInstance(constLocaledesiredLocale,
UNumberFormatStyle style,
UErrorCodeerrorCode 
)
static

Create a specific styleNumberFormat for the specified locale.

NOTE: New users are strongly encouraged to useicu::number::NumberFormatter instead ofNumberFormat.

Parameters
desiredLocalethe given locale.
stylethe given style.
errorCodeOutput param filled with success/failure status.
Returns
A newNumberFormat instance.
Stable:
ICU 4.8

◆ createInstance()[2/3]

staticNumberFormat* icu::NumberFormat::createInstance(constLocaleinLocale,
UErrorCode 
)
static

Create a default styleNumberFormat for the specified locale.

The default formatting style is locale dependent.

Parameters
inLocalethe given locale.

NOTE: New users are strongly encouraged to useicu::number::NumberFormatter instead ofNumberFormat.

Stable:
ICU 2.0

◆ createInstance()[3/3]

staticNumberFormat* icu::NumberFormat::createInstance(UErrorCode)
static

Create a default styleNumberFormat for the current default locale.

The default formatting style is locale dependent.

NOTE: New users are strongly encouraged to useicu::number::NumberFormatter instead ofNumberFormat.

Stable:
ICU 2.0

◆ createPercentInstance()[1/2]

staticNumberFormat* icu::NumberFormat::createPercentInstance(constLocaleinLocale,
UErrorCode 
)
static

Returns a percentage format for the specified locale.

NOTE: New users are strongly encouraged to useicu::number::NumberFormatter instead ofNumberFormat.

Parameters
inLocalethe given locale.
Stable:
ICU 2.0

◆ createPercentInstance()[2/2]

staticNumberFormat* icu::NumberFormat::createPercentInstance(UErrorCode)
static

Returns a percentage format for the current default locale.

NOTE: New users are strongly encouraged to useicu::number::NumberFormatter instead ofNumberFormat.

Stable:
ICU 2.0

◆ createScientificInstance()[1/2]

staticNumberFormat* icu::NumberFormat::createScientificInstance(constLocaleinLocale,
UErrorCode 
)
static

Returns a scientific format for the specified locale.

NOTE: New users are strongly encouraged to useicu::number::NumberFormatter instead ofNumberFormat.

Parameters
inLocalethe given locale.
Stable:
ICU 2.0

◆ createScientificInstance()[2/2]

staticNumberFormat* icu::NumberFormat::createScientificInstance(UErrorCode)
static

Returns a scientific format for the current default locale.

NOTE: New users are strongly encouraged to useicu::number::NumberFormatter instead ofNumberFormat.

Stable:
ICU 2.0

◆ createSharedInstance()

static const SharedNumberFormat* icu::NumberFormat::createSharedInstance(constLocaleinLocale,
UNumberFormatStyle style,
UErrorCodestatus 
)
static

ICU use only.

Returns handle to the shared, cachedNumberFormat instance for given locale. On success, caller must call removeRef() on returned value once it is done with the shared instance.

Internal:
Do not use. This API is for internal use only.

◆ format()[1/20]

virtualUnicodeString& icu::NumberFormat::format(constFormattableobj,
UnicodeStringappendTo,
FieldPositionpos,
UErrorCodestatus 
) const
overridevirtual

Format an object to produce a string.

This method handlesFormattable objects with numeric types. If theFormattable object type is not a numeric type, then it returns a failing UErrorCode.

Parameters
objThe object to format.
appendToOutput parameter to receive result. Result is appended to existing contents.
posOn input: an alignment field, if desired. On output: the offsets of the alignment field.
statusOutput param filled with success/failure status.
Returns
Reference to 'appendTo' parameter.
Stable:
ICU 2.0

Implementsicu::Format.

◆ format()[2/20]

virtualU_I18N_APIUnicodeString& icu::Format::format

Format an object to produce a string.

This is a pure virtual method which subclasses must implement. This method allows polymorphic formatting ofFormattable objects. If a subclass ofFormat receives aFormattable object type it doesn't handle (e.g., if a numericFormattable is passed to aDateFormat object) then it returns a failing UErrorCode.

Parameters
objThe object to format.
appendToOutput parameter to receive result. Result is appended to existing contents.
posOn input: an alignment field, if desired. On output: the offsets of the alignment field.
statusOutput param filled with success/failure status.
Returns
Reference to 'appendTo' parameter.
Stable:
ICU 2.0

◆ format()[3/20]

virtualU_I18N_APIUnicodeString& icu::Format::format

Format an object to produce a string.

Subclasses should override this method. This method allows polymorphic formatting ofFormattable objects. If a subclass ofFormat receives aFormattable object type it doesn't handle (e.g., if a numericFormattable is passed to aDateFormat object) then it returns a failing UErrorCode.

Parameters
objThe object to format.
appendToOutput parameter to receive result. Result is appended to existing contents.
posIterOn return, can be used to iterate over positions of fields generated by this format call.
statusOutput param filled with success/failure status.
Returns
Reference to 'appendTo' parameter.
Stable:
ICU 4.4

◆ format()[4/20]

virtualUnicodeString& icu::NumberFormat::format(constFormattableobj,
UnicodeStringappendTo,
FieldPositionIteratorposIter,
UErrorCodestatus 
) const
overridevirtual

Format an object to produce a string.

This method handlesFormattable objects with numeric types. If theFormattable object type is not a numeric type, then it returns a failing UErrorCode.

Parameters
objThe object to format.
appendToOutput parameter to receive result. Result is appended to existing contents.
posIterOn return, can be used to iterate over positions of fields generated by this format call. Can be nullptr.
statusOutput param filled with success/failure status.
Returns
Reference to 'appendTo' parameter.
Stable:
ICU 4.4

Reimplemented fromicu::Format.

◆ format()[5/20]

U_I18N_APIUnicodeString& icu::Format::format

Formats an object to produce a string.

Parameters
objThe object to format.
appendToOutput parameter to receive result. Result is appended to existing contents.
statusOutput parameter filled in with success or failure status.
Returns
Reference to 'appendTo' parameter.
Stable:
ICU 2.0

◆ format()[6/20]

virtualUnicodeString& icu::NumberFormat::format(const number::impl::DecimalQuantity & number,
UnicodeStringappendTo,
FieldPositionpos,
UErrorCodestatus 
) const
virtual

Format a decimal number.

The number is a DecimalQuantity wrapper onto a floating point decimal number. The default implementation inNumberFormat converts the decimal number to a double and formats that. Subclasses ofNumberFormat that want to specifically handle big decimal numbers must override this method. classDecimalFormat does so.

Parameters
numberThe number, a DecimalQuantity format Decimal Floating Point.
appendToOutput parameter to receive result. Result is appended to existing contents.
posOn input: an alignment field, if desired. On output: the offsets of the alignment field.
statusOutput param filled with success/failure status.
Returns
Reference to 'appendTo' parameter.
Internal:
Do not use. This API is for internal use only.

Reimplemented inicu::RuleBasedNumberFormat, andicu::DecimalFormat.

◆ format()[7/20]

virtualUnicodeString& icu::NumberFormat::format(const number::impl::DecimalQuantity & number,
UnicodeStringappendTo,
FieldPositionIteratorposIter,
UErrorCodestatus 
) const
virtual

Format a decimal number.

The number is a DecimalQuantity wrapper onto a floating point decimal number. The default implementation inNumberFormat converts the decimal number to a double and formats that. Subclasses ofNumberFormat that want to specifically handle big decimal numbers must override this method. classDecimalFormat does so.

Parameters
numberThe number, a DecimalQuantity format Decimal Floating Point.
appendToOutput parameter to receive result. Result is appended to existing contents.
posIterOn return, can be used to iterate over positions of fields generated by this format call.
statusOutput param filled with success/failure status.
Returns
Reference to 'appendTo' parameter.
Internal:
Do not use. This API is for internal use only.

Reimplemented inicu::DecimalFormat.

◆ format()[8/20]

UnicodeString& icu::NumberFormat::format(double number,
UnicodeStringappendTo 
) const

Format a double number.

These methods call theNumberFormat pure virtualformat() methods with the defaultFieldPosition.

Parameters
numberThe value to be formatted.
appendToOutput parameter to receive result. Result is appended to existing contents.
Returns
Reference to 'appendTo' parameter.
Stable:
ICU 2.0

◆ format()[9/20]

virtualUnicodeString& icu::NumberFormat::format(double number,
UnicodeStringappendTo,
FieldPositionpos 
) const
pure virtual

Format a double number.

Concrete subclasses must implement these pure virtual methods.

Parameters
numberThe value to be formatted.
appendToOutput parameter to receive result. Result is appended to existing contents.
posOn input: an alignment field, if desired. On output: the offsets of the alignment field.
Returns
Reference to 'appendTo' parameter.
Stable:
ICU 2.0

Implemented inicu::RuleBasedNumberFormat,icu::DecimalFormat, andicu::ChoiceFormat.

◆ format()[10/20]

virtualUnicodeString& icu::NumberFormat::format(double number,
UnicodeStringappendTo,
FieldPositionpos,
UErrorCodestatus 
) const
virtual

Format a double number.

By default, the parent function simply calls the base class and does not return an error status. Therefore, the status may be ignored in some subclasses.

Parameters
numberThe value to be formatted.
appendToOutput parameter to receive result. Result is appended to existing contents.
posOn input: an alignment field, if desired. On output: the offsets of the alignment field.
statuserror status
Returns
Reference to 'appendTo' parameter.
Internal:
Do not use. This API is for internal use only.

Reimplemented inicu::DecimalFormat.

◆ format()[11/20]

virtualUnicodeString& icu::NumberFormat::format(double number,
UnicodeStringappendTo,
FieldPositionIteratorposIter,
UErrorCodestatus 
) const
virtual

Format a double number.

Subclasses must implement this method.

Parameters
numberThe value to be formatted.
appendToOutput parameter to receive result. Result is appended to existing contents.
posIterOn return, can be used to iterate over positions of fields generated by this format call. Can be nullptr.
statusOutput param filled with success/failure status.
Returns
Reference to 'appendTo' parameter.
Stable:
ICU 4.4

Reimplemented inicu::DecimalFormat.

◆ format()[12/20]

UnicodeString& icu::NumberFormat::format(int32_t number,
UnicodeStringappendTo 
) const

Format a long number.

These methods call theNumberFormat pure virtualformat() methods with the defaultFieldPosition.

Parameters
numberThe value to be formatted.
appendToOutput parameter to receive result. Result is appended to existing contents.
Returns
Reference to 'appendTo' parameter.
Stable:
ICU 2.0

◆ format()[13/20]

virtualUnicodeString& icu::NumberFormat::format(int32_t number,
UnicodeStringappendTo,
FieldPositionpos 
) const
pure virtual

Format a long number.

Concrete subclasses must implement these pure virtual methods.

Parameters
numberThe value to be formatted.
appendToOutput parameter to receive result. Result is appended to existing contents.
posOn input: an alignment field, if desired. On output: the offsets of the alignment field.
Returns
Reference to 'appendTo' parameter.
Stable:
ICU 2.0

Implemented inicu::RuleBasedNumberFormat,icu::DecimalFormat, andicu::ChoiceFormat.

◆ format()[14/20]

virtualUnicodeString& icu::NumberFormat::format(int32_t number,
UnicodeStringappendTo,
FieldPositionpos,
UErrorCodestatus 
) const
virtual

Format a long number.

Concrete subclasses may override this function to provide status return.

Parameters
numberThe value to be formatted.
appendToOutput parameter to receive result. Result is appended to existing contents.
posOn input: an alignment field, if desired. On output: the offsets of the alignment field.
statusthe output status.
Returns
Reference to 'appendTo' parameter.
Internal:
Do not use. This API is for internal use only.

Reimplemented inicu::DecimalFormat.

◆ format()[15/20]

virtualUnicodeString& icu::NumberFormat::format(int32_t number,
UnicodeStringappendTo,
FieldPositionIteratorposIter,
UErrorCodestatus 
) const
virtual

Format an int32 number.

Subclasses must implement this method.

Parameters
numberThe value to be formatted.
appendToOutput parameter to receive result. Result is appended to existing contents.
posIterOn return, can be used to iterate over positions of fields generated by this format call. Can be nullptr.
statusOutput param filled with success/failure status.
Returns
Reference to 'appendTo' parameter.
Stable:
ICU 4.4

Reimplemented inicu::DecimalFormat.

◆ format()[16/20]

UnicodeString& icu::NumberFormat::format(int64_t number,
UnicodeStringappendTo 
) const

Format an int64 number.

These methods call theNumberFormat pure virtualformat() methods with the defaultFieldPosition.

Parameters
numberThe value to be formatted.
appendToOutput parameter to receive result. Result is appended to existing contents.
Returns
Reference to 'appendTo' parameter.
Stable:
ICU 2.8

◆ format()[17/20]

virtualUnicodeString& icu::NumberFormat::format(int64_t number,
UnicodeStringappendTo,
FieldPositionpos 
) const
virtual

Format an int64 number.

(Not abstract to retain compatibility with earlier releases, however subclasses should override this method as it just delegates to format(int32_t number...);

Parameters
numberThe value to be formatted.
appendToOutput parameter to receive result. Result is appended to existing contents.
posOn input: an alignment field, if desired. On output: the offsets of the alignment field.
Returns
Reference to 'appendTo' parameter.
Stable:
ICU 2.8

Reimplemented inicu::RuleBasedNumberFormat,icu::DecimalFormat, andicu::ChoiceFormat.

◆ format()[18/20]

virtualUnicodeString& icu::NumberFormat::format(int64_t number,
UnicodeStringappendTo,
FieldPositionpos,
UErrorCodestatus 
) const
virtual

Format an int64 number.

(Not abstract to retain compatibility with earlier releases, however subclasses should override this method as it just delegates to format(int32_t number...);

Parameters
numberThe value to be formatted.
appendToOutput parameter to receive result. Result is appended to existing contents.
posOn input: an alignment field, if desired. On output: the offsets of the alignment field.
statusOutput param filled with success/failure status.
Returns
Reference to 'appendTo' parameter.
Internal:
Do not use. This API is for internal use only.

Reimplemented inicu::DecimalFormat.

◆ format()[19/20]

virtualUnicodeString& icu::NumberFormat::format(int64_t number,
UnicodeStringappendTo,
FieldPositionIteratorposIter,
UErrorCodestatus 
) const
virtual

Format an int64 number.

Subclasses must implement this method.

Parameters
numberThe value to be formatted.
appendToOutput parameter to receive result. Result is appended to existing contents.
posIterOn return, can be used to iterate over positions of fields generated by this format call. Can be nullptr.
statusOutput param filled with success/failure status.
Returns
Reference to 'appendTo' parameter.
Stable:
ICU 4.4

Reimplemented inicu::DecimalFormat.

◆ format()[20/20]

virtualUnicodeString& icu::NumberFormat::format(StringPiece number,
UnicodeStringappendTo,
FieldPositionIteratorposIter,
UErrorCodestatus 
) const
virtual

Format a decimal number.

Subclasses must implement this method. The syntax of the unformatted number is a "numeric string" as defined in the Decimal Arithmetic Specification, available athttp://speleotrove.com/decimal

Parameters
numberThe unformatted number, as a string, to be formatted.
appendToOutput parameter to receive result. Result is appended to existing contents.
posIterOn return, can be used to iterate over positions of fields generated by this format call. Can be nullptr.
statusOutput param filled with success/failure status.
Returns
Reference to 'appendTo' parameter.
Stable:
ICU 4.4

Reimplemented inicu::DecimalFormat.

◆ getAvailableLocales()[1/2]

staticStringEnumeration* icu::NumberFormat::getAvailableLocales()
static

Return aStringEnumeration over the locales available at the time of the call, including registered locales.

Returns
aStringEnumeration over the locales available at the time of the call
Stable:
ICU 2.6

◆ getAvailableLocales()[2/2]

static constLocale* icu::NumberFormat::getAvailableLocales(int32_t & count)
static

Get the set of Locales for which NumberFormats are installed.

Parameters
countOutput param to receive the size of the locales
Stable:
ICU 2.0

◆ getContext()

virtualUDisplayContext icu::NumberFormat::getContext(UDisplayContextType type,
UErrorCodestatus 
) const
virtual

Get the formatter's UDisplayContext value for the specified UDisplayContextType, such as UDISPCTX_TYPE_CAPITALIZATION.

Parameters
typeThe UDisplayContextType whose value to return
statusInput/output status. If at entry this indicates a failure status, the function will do nothing; otherwise this will be updated with any new status from the function.
Returns
The UDisplayContextValue for the specified type.
Stable:
ICU 53

◆ getCurrency()

const char16_t* icu::NumberFormat::getCurrency() const

Gets the currency used to display currency amounts.

This may be an empty string for some subclasses.

Returns
a 3-letter null-terminated ISO code indicating the currency in use, or a pointer to the empty string.
Stable:
ICU 2.6

◆ getDynamicClassID()

virtualUClassID icu::NumberFormat::getDynamicClassID() const
overridepure virtual

Returns a unique class ID POLYMORPHICALLY.

Pure virtual override. This method is to implement a simple version of RTTI, since not all C++ compilers support genuine RTTI. Polymorphicoperator==() andclone() methods call this method.

Returns
The class ID for this object. All objects of a given class have the same class ID. Objects of other classes have different class IDs.
Stable:
ICU 2.0

Reimplemented fromicu::UObject.

Implemented inicu::RuleBasedNumberFormat,icu::DecimalFormat,icu::CompactDecimalFormat, andicu::ChoiceFormat.

◆ getEffectiveCurrency()

virtual void icu::NumberFormat::getEffectiveCurrency(char16_t * result,
UErrorCodeec 
) const
protectedvirtual

Returns the currency in effect for this formatter.

Subclasses should override this method as needed. UnlikegetCurrency(), this method should never return "".

Returns
output parameter for null-terminated result, which must have a capacity of at least 4
Internal:
Do not use. This API is for internal use only.

◆ getMaximumFractionDigits()

int32_t icu::NumberFormat::getMaximumFractionDigits() const

Returns the maximum number of digits allowed in the fraction portion of a number.

Returns
the maximum number of digits allowed in the fraction portion of a number.
See also
setMaximumFractionDigits
Stable:
ICU 2.0

◆ getMaximumIntegerDigits()

int32_t icu::NumberFormat::getMaximumIntegerDigits() const

Returns the maximum number of digits allowed in the integer portion of a number.

Returns
the maximum number of digits allowed in the integer portion of a number.
See also
setMaximumIntegerDigits
Stable:
ICU 2.0

◆ getMinimumFractionDigits()

int32_t icu::NumberFormat::getMinimumFractionDigits() const

Returns the minimum number of digits allowed in the fraction portion of a number.

Returns
the minimum number of digits allowed in the fraction portion of a number.
See also
setMinimumFractionDigits
Stable:
ICU 2.0

◆ getMinimumIntegerDigits()

int32_t icu::NumberFormat::getMinimumIntegerDigits() const

Returns the minimum number of digits allowed in the integer portion of a number.

Returns
the minimum number of digits allowed in the integer portion of a number.
See also
setMinimumIntegerDigits
Stable:
ICU 2.0

◆ getRoundingMode()

virtualERoundingMode icu::NumberFormat::getRoundingMode() const
virtual

Get the rounding mode.

This will always return NumberFormat::ERoundingMode::kRoundUnnecessary if the subclass does not support rounding.

Returns
A rounding mode
Stable:
ICU 60

Reimplemented inicu::RuleBasedNumberFormat, andicu::DecimalFormat.

◆ getStaticClassID()

staticUClassID icu::NumberFormat::getStaticClassID()
static

Return the class ID for this class.

This is useful for comparing to a return value fromgetDynamicClassID(). Note that, becauseNumberFormat is an abstract base class, no fully constructed object will have the class ID returned byNumberFormat::getStaticClassID().

Returns
The class ID for all objects of this class.
Stable:
ICU 2.0

◆ internalCreateInstance()

staticNumberFormat* icu::NumberFormat::internalCreateInstance(constLocaledesiredLocale,
UNumberFormatStyle style,
UErrorCodeerrorCode 
)
static

ICU use only.

CreatesNumberFormat instance without using the cache.

Internal:
Do not use. This API is for internal use only.

◆ isGroupingUsed()

UBool icu::NumberFormat::isGroupingUsed() const

Returns true if grouping is used in this format.

For example, in the English locale, with grouping on, the number 1234567 might be formatted as "1,234,567". The grouping separator as well as the size of each group is locale dependent and is determined by sub-classes ofNumberFormat.

See also
setGroupingUsed
Stable:
ICU 2.0

◆ isLenient()

UBool icu::NumberFormat::isLenient() const
inlinevirtual

Returns whether lenient parsing is enabled (it is off by default).

Returns
true if lenient parsing is enabled,false otherwise.
See also
setLenient
Stable:
ICU 4.8

Reimplemented inicu::RuleBasedNumberFormat.

Definition at line1274 of filenumfmt.h.

◆ isParseIntegerOnly()

UBool icu::NumberFormat::isParseIntegerOnly() const
inline

Return true if this format will parse numbers as integers only.

For example in the English locale, with ParseIntegerOnly true, the string "1234." would be parsed as the integer value 1234 and parsing would stop at the "." character. Of course, the exact format accepted by the parse operation is locale dependent and determined by sub-classes ofNumberFormat.

Returns
true if this format will parse numbers as integers only.
Stable:
ICU 2.0

Definition at line1268 of filenumfmt.h.

◆ makeInstance()

staticNumberFormat* icu::NumberFormat::makeInstance(constLocaledesiredLocale,
UNumberFormatStyle style,
UBool mustBeDecimalFormat,
UErrorCodeerrorCode 
)
staticprotected

Creates the specified number format style of the desired locale.

If mustBeDecimalFormat is true, then the returned pointer is either aDecimalFormat or it is nullptr.

Internal:
Do not use. This API is for internal use only.

◆ operator=()

NumberFormat& icu::NumberFormat::operator=(constNumberFormat)
protected

Assignment operator.

Stable:
ICU 2.0

◆ operator==()

virtual bool icu::NumberFormat::operator==(constFormatother) const
overridevirtual

Return true if the givenFormat objects are semantically equal.

Objects of different subclasses are considered unequal.

Returns
true if the givenFormat objects are semantically equal.
Stable:
ICU 2.0

Implementsicu::Format.

Reimplemented inicu::RuleBasedNumberFormat,icu::DecimalFormat, andicu::ChoiceFormat.

◆ parse()[1/2]

virtual void icu::NumberFormat::parse(constUnicodeStringtext,
Formattableresult,
ParsePositionparsePosition 
) const
pure virtual

Return a long if possible (e.g.

within range LONG_MAX, LONG_MAX], and with no decimals), otherwise a double. If IntegerOnly is set, will stop at a decimal point (or equivalent; e.g. for rational numbers "1 2/3", will stop after the 1).

If no object can be parsed, index is unchanged, and nullptr is returned.

This is a pure virtual which concrete subclasses must implement.

Parameters
textThe text to be parsed.
resultFormattable to be set to the parse result. If parse fails, return contents are undefined.
parsePositionThe position to start parsing at on input. On output, moved to after the last successfully parse character. On parse failure, does not change.
Stable:
ICU 2.0

Implemented inicu::RuleBasedNumberFormat,icu::DecimalFormat,icu::CompactDecimalFormat, andicu::ChoiceFormat.

◆ parse()[2/2]

virtual void icu::NumberFormat::parse(constUnicodeStringtext,
Formattableresult,
UErrorCodestatus 
) const
virtual

Parse a string as a numeric value, and return aFormattable numeric object.

This method parses integers only if IntegerOnly is set.

Parameters
textThe text to be parsed.
resultFormattable to be set to the parse result. If parse fails, return contents are undefined.
statusOutput parameter set to a failure error code when a failure occurs. The error code when the string fails to parse is U_INVALID_FORMAT_ERROR, unless overridden by a subclass.
See also
NumberFormat::isParseIntegerOnly
Stable:
ICU 2.0

Reimplemented inicu::CompactDecimalFormat.

◆ parseCurrency()

virtualCurrencyAmount* icu::NumberFormat::parseCurrency(constUnicodeStringtext,
ParsePositionpos 
) const
virtual

Parses text from the given string as a currency amount.

Unlike theparse() method, this method will attempt to parse a generic currency name, searching for a match of this object's locale's currency display names, or for a 3-letter ISO currency code. This method will fail if this format is not a currency format, that is, if it does not contain the currency pattern symbol (U+00A4) in its prefix or suffix.

Parameters
textthe string to parse
posinput-output position; on input, the position within text to match; must have 0 <= pos.getIndex() < text.length(); on output, the position after the last matched character. If the parse fails, the position in unchanged upon output.
Returns
if parse succeeds, a pointer to a newly-createdCurrencyAmount object (owned by the caller) containing information about the parsed currency; if parse fails, this is nullptr.
Stable:
ICU 49

Reimplemented inicu::DecimalFormat, andicu::CompactDecimalFormat.

◆ parseObject()

virtual void icu::NumberFormat::parseObject(constUnicodeStringsource,
Formattableresult,
ParsePositionparse_pos 
) const
overridevirtual

Parse a string to produce an object.

This methods handles parsing of numeric strings intoFormattable objects with numeric types.

Before calling, set parse_pos.index to the offset you want to start parsing at in the source. After calling, parse_pos.index indicates the position after the successfully parsed text. If an error occurs, parse_pos.index is unchanged.

When parsing, leading whitespace is discarded (with successful parse), while trailing whitespace is left as is.

SeeFormat::parseObject() for more.

Parameters
sourceThe string to be parsed into an object.
resultFormattable to be set to the parse result. If parse fails, return contents are undefined.
parse_posThe position to start parsing at. Upon return this param is set to the position after the last character successfully parsed. If the source is not parsed successfully, this param will remain unchanged.
Returns
A newly created Formattable* object, or nullptr on failure. The caller owns this and should delete it when done.
Stable:
ICU 2.0

Implementsicu::Format.

◆ registerFactory()

staticURegistryKey icu::NumberFormat::registerFactory(NumberFormatFactorytoAdopt,
UErrorCodestatus 
)
static

Register a newNumberFormatFactory.

The factory will be adopted. Because ICU may choose to cacheNumberFormat objects internally, this must be called at application startup, prior to any calls toNumberFormat::createInstance to avoid undefined behavior.

Parameters
toAdopttheNumberFormatFactory instance to be adopted
statusthe in/out status code, no special meanings are assigned
Returns
a registry key that can be used to unregister this factory
Stable:
ICU 2.6

◆ setContext()

virtual void icu::NumberFormat::setContext(UDisplayContext value,
UErrorCodestatus 
)
virtual

Set a particular UDisplayContext value in the formatter, such as UDISPCTX_CAPITALIZATION_FOR_STANDALONE.

Parameters
valueThe UDisplayContext value to set.
statusInput/output status. If at entry this indicates a failure status, the function will do nothing; otherwise this will be updated with any new status from the function.
Stable:
ICU 53

Reimplemented inicu::RuleBasedNumberFormat.

◆ setCurrency()

virtual void icu::NumberFormat::setCurrency(const char16_t * theCurrency,
UErrorCodeec 
)
virtual

Sets the currency used to display currency amounts.

This takes effect immediately, if this format is a currency format. If this format is not a currency format, then the currency is used if and when this object becomes a currency format.

Parameters
theCurrencya 3-letter ISO code indicating new currency to use. It need not be null-terminated. May be the empty string or nullptr to indicate no currency.
ecinput-output error code
Stable:
ICU 3.0

Reimplemented inicu::DecimalFormat.

◆ setGroupingUsed()

virtual void icu::NumberFormat::setGroupingUsed(UBool newValue)
virtual

Set whether or not grouping will be used in this format.

Parameters
newValueTrue, grouping will be used in this format.
See also
getGroupingUsed
Stable:
ICU 2.0

Reimplemented inicu::DecimalFormat.

◆ setLenient()

virtual void icu::NumberFormat::setLenient(UBool enable)
virtual

Sets whether lenient parsing should be enabled (it is off by default).

Parameters
enabletrue if lenient parsing should be used,false otherwise.
Stable:
ICU 4.8

Reimplemented inicu::RuleBasedNumberFormat, andicu::DecimalFormat.

◆ setMaximumFractionDigits()

virtual void icu::NumberFormat::setMaximumFractionDigits(int32_t newValue)
virtual

Sets the maximum number of digits allowed in the fraction portion of a number.

maximumFractionDigits must be >= minimumFractionDigits. If the new value for maximumFractionDigits is less than the current value of minimumFractionDigits, then minimumFractionDigits will also be set to the new value.

Parameters
newValuethe new value to be set.
See also
getMaximumFractionDigits
Stable:
ICU 2.0

Reimplemented inicu::DecimalFormat.

◆ setMaximumIntegerDigits()

virtual void icu::NumberFormat::setMaximumIntegerDigits(int32_t newValue)
virtual

Sets the maximum number of digits allowed in the integer portion of a number.

maximumIntegerDigits must be >= minimumIntegerDigits. If the new value for maximumIntegerDigits is less than the current value of minimumIntegerDigits, then minimumIntegerDigits will also be set to the new value.

Parameters
newValuethe new value for the maximum number of digits allowed in the integer portion of a number.
See also
getMaximumIntegerDigits
Stable:
ICU 2.0

Reimplemented inicu::DecimalFormat.

◆ setMinimumFractionDigits()

virtual void icu::NumberFormat::setMinimumFractionDigits(int32_t newValue)
virtual

Sets the minimum number of digits allowed in the fraction portion of a number.

minimumFractionDigits must be <= maximumFractionDigits. If the new value for minimumFractionDigits exceeds the current value of maximumFractionDigits, then maximumIntegerDigits will also be set to the new value

Parameters
newValuethe new value to be set.
See also
getMinimumFractionDigits
Stable:
ICU 2.0

Reimplemented inicu::DecimalFormat.

◆ setMinimumIntegerDigits()

virtual void icu::NumberFormat::setMinimumIntegerDigits(int32_t newValue)
virtual

Sets the minimum number of digits allowed in the integer portion of a number.

minimumIntegerDigits must be <= maximumIntegerDigits. If the new value for minimumIntegerDigits exceeds the current value of maximumIntegerDigits, then maximumIntegerDigits will also be set to the new value.

Parameters
newValuethe new value to be set.
See also
getMinimumIntegerDigits
Stable:
ICU 2.0

Reimplemented inicu::DecimalFormat.

◆ setParseIntegerOnly()

virtual void icu::NumberFormat::setParseIntegerOnly(UBool value)
virtual

Sets whether or not numbers should be parsed as integers only.

Parameters
valueset True, this format will parse numbers as integers only.
See also
isParseIntegerOnly
Stable:
ICU 2.0

Reimplemented inicu::DecimalFormat.

◆ setRoundingMode()

virtual void icu::NumberFormat::setRoundingMode(ERoundingMode roundingMode)
virtual

Set the rounding mode.

If a subclass does not support rounding, this will do nothing.

Parameters
roundingModeA rounding mode
Stable:
ICU 60

Reimplemented inicu::RuleBasedNumberFormat, andicu::DecimalFormat.

◆ unregister()

staticUBool icu::NumberFormat::unregister(URegistryKey key,
UErrorCodestatus 
)
static

Unregister a previously-registeredNumberFormatFactory using the key returned from the register call.

Key becomes invalid after a successful call and should not be used again. TheNumberFormatFactory corresponding to the key will be deleted. Because ICU may choose to cacheNumberFormat objects internally, this should be called during application shutdown, after all calls toNumberFormat::createInstance to avoid undefined behavior.

Parameters
keythe registry key returned by a previous call to registerFactory
statusthe in/out status code, no special meanings are assigned
Returns
true if the factory for the key was successfully unregistered
Stable:
ICU 2.6

Field Documentation

◆ gDefaultMaxIntegerDigits

const int32_t icu::NumberFormat::gDefaultMaxIntegerDigits
staticprotected
Internal:
Do not use.

This API is for internal use only.

Definition at line1163 of filenumfmt.h.

◆ gDefaultMinIntegerDigits

const int32_t icu::NumberFormat::gDefaultMinIntegerDigits
staticprotected
Internal:
Do not use.

This API is for internal use only.

Definition at line1165 of filenumfmt.h.


The documentation for this class was generated from the following file:

Generated by doxygen 1.9.1
[8]ページ先頭

©2009-2025 Movatter.jp