ICU 62.1
62.1
|
C++ API: Library for localized number formatting introduced in ICU 60. More...
#include "unicode/utypes.h"
#include "unicode/appendable.h"
#include "unicode/dcfmtsym.h"
#include "unicode/currunit.h"
#include "unicode/fieldpos.h"
#include "unicode/fpositer.h"
#include "unicode/measunit.h"
#include "unicode/nounit.h"
#include "unicode/plurrule.h"
#include "unicode/ucurr.h"
#include "unicode/unum.h"
#include "unicode/unumberformatter.h"
#include "unicode/uobject.h"
Go to the source code of this file.
Data Structures | |
class | icu::number::Notation |
A class that defines the notation style to be used when formatting numbers in NumberFormatter. More... | |
struct | icu::number::Notation::NotationUnion::ScientificSettings |
class | icu::number::ScientificNotation |
A class that defines the scientific notation style to be used when formatting numbers in NumberFormatter. More... | |
class | icu::number::Precision |
A class that defines the rounding precision to be used when formatting numbers in NumberFormatter. More... | |
struct | icu::number::Precision::PrecisionUnion::FractionSignificantSettings |
struct | icu::number::Precision::PrecisionUnion::IncrementSettings |
class | icu::number::FractionPrecision |
A class that defines a rounding precision based on a number of fraction places and optionally significant digits to be used when formatting numbers in NumberFormatter. More... | |
class | icu::number::CurrencyPrecision |
A class that defines a rounding precision parameterized by a currency to be used when formatting numbers in NumberFormatter. More... | |
class | icu::number::IncrementPrecision |
A class that defines a rounding precision parameterized by a rounding increment to be used when formatting numbers in NumberFormatter. More... | |
class | icu::number::IntegerWidth |
A class that defines the strategy for padding and truncating integers before the decimal separator. More... | |
class | icu::number::Scale |
A class that defines a quantity by which a number should be multiplied when formatting. More... | |
class | icu::number::impl::SymbolsWrapper |
class | icu::number::impl::Grouper |
class | icu::number::impl::Padder |
struct | icu::number::impl::MacroProps |
class | icu::number::NumberFormatterSettings< Derived > |
An abstract base class for specifying settings related to number formatting. More... | |
class | icu::number::UnlocalizedNumberFormatter |
A NumberFormatter that does not yet have a locale. More... | |
class | icu::number::LocalizedNumberFormatter |
A NumberFormatter that has a locale associated with it; this means .format() methods are available. More... | |
class | icu::number::FormattedNumber |
The result of a number formatting operation. More... | |
class | icu::number::NumberFormatter |
See the main description in numberformatter.h for documentation and examples. More... | |
Namespaces | |
icu | |
File coll.h. | |
Typedefs | |
typedef int16_t | icu::number::impl::digits_t |
Datatype for minimum/maximum fraction digits. More... | |
typedef Notation | icu::number::CompactNotation |
typedef Notation | icu::number::SimpleNotation |
typedef Precision | icu::number::SignificantDigitsPrecision |
typedef Precision | icu::number::Rounder |
typedef FractionPrecision | icu::number::FractionRounder |
typedef IncrementPrecision | icu::number::IncrementRounder |
typedef CurrencyPrecision | icu::number::CurrencyRounder |
C++ API: Library for localized number formatting introduced in ICU 60.
This library was introduced in ICU 60 to simplify the process of formatting localized number strings. Basic usage examples:
// Most basic usage: NumberFormatter::withLocale(...).format(123).toString(); // 1,234 in en-US
// Custom notation, unit, and rounding precision: NumberFormatter::with() .notation(Notation::compactShort()) .unit(CurrencyUnit("EUR", status)) .precision(Precision::maxDigits(2)) .locale(...) .format(1234) .toString(); // €1.2K in en-US
// Create a formatter in a singleton for use later: static const LocalizedNumberFormatter formatter = NumberFormatter::withLocale(...) .unit(NoUnit::percent()) .precision(Precision::fixedFraction(3)); formatter.format(5.9831).toString(); // 5.983% in en-US
// Create a "template" in a singleton but without setting a locale until the call site: static const UnlocalizedNumberFormatter template = NumberFormatter::with() .sign(UNumberSignDisplay::UNUM_SIGN_ALWAYS) .adoptUnit(MeasureUnit::createMeter(status)) .unitWidth(UNumberUnitWidth::UNUM_UNIT_WIDTH_FULL_NAME); template.locale(...).format(1234).toString(); // +1,234 meters in en-US
This API offers more features than DecimalFormat and is geared toward new users of ICU.
NumberFormatter instances are immutable and thread safe. This means that invoking a configuration method has no effect on the receiving instance; you must store and use the new number formatter instance it returns instead.
UnlocalizedNumberFormatter formatter = UnlocalizedNumberFormatter::with().notation(Notation::scientific()); formatter.precision(Precision.maxFraction(2)); // does nothing! formatter.locale(Locale.getEnglish()).format(9.8765).toString(); // prints "9.8765E0", not "9.88E0"
This API is based on the fluent design pattern popularized by libraries such as Google's Guava. For extensive details on the design of this API, read the design doc.
Definition in file numberformatter.h.
typedef int16_t icu::number::impl::digits_t |
Datatype for minimum/maximum fraction digits.
Must be able to hold kMaxIntFracSig.
Definition at line 116 of file numberformatter.h.