ICU 73.2  73.2
Data Structures | Public Member Functions | Static Public Member Functions
icu::ScientificNumberFormatter Class Reference

A formatter that formats numbers in user-friendly scientific notation. More...

#include <scientificnumberformatter.h>

Inheritance diagram for icu::ScientificNumberFormatter:
icu::UObject icu::UMemory

Data Structures

class  MarkupStyle
class  Style
class  SuperscriptStyle

Public Member Functions

ScientificNumberFormatterclone () const
 Returns a copy of this object.
virtual ~ScientificNumberFormatter ()
 Destructor.
UnicodeStringformat (const Formattable &number, UnicodeString &appendTo, UErrorCode &status) const
 Formats a number into user friendly scientific notation.

Static Public Member Functions

static ScientificNumberFormattercreateSuperscriptInstance (DecimalFormat *fmtToAdopt, UErrorCode &status)
 Creates a ScientificNumberFormatter instance that uses superscript characters for exponents.
static ScientificNumberFormattercreateSuperscriptInstance (const Locale &locale, UErrorCode &status)
 Creates a ScientificNumberFormatter instance that uses superscript characters for exponents for this locale.
static ScientificNumberFormattercreateMarkupInstance (DecimalFormat *fmtToAdopt, const UnicodeString &beginMarkup, const UnicodeString &endMarkup, UErrorCode &status)
 Creates a ScientificNumberFormatter instance that uses markup for exponents.
static ScientificNumberFormattercreateMarkupInstance (const Locale &locale, const UnicodeString &beginMarkup, const UnicodeString &endMarkup, UErrorCode &status)
 Creates a ScientificNumberFormatter instance that uses markup for exponents for this locale.

Detailed Description

A formatter that formats numbers in user-friendly scientific notation.

Sample code:

 UErrorCode status = U_ZERO_ERROR;
 LocalPointer<ScientificNumberFormatter> fmt(
         ScientificNumberFormatter::createMarkupInstance(
                 "en", "<sup>", "</sup>", status));
 if (U_FAILURE(status)) {
     return;
 }
 UnicodeString appendTo;
 // appendTo = "1.23456x10<sup>-78</sup>"
 fmt->format(1.23456e-78, appendTo, status);
 
Stable:
ICU 55

Definition at line 52 of file scientificnumberformatter.h.


Constructor & Destructor Documentation

Destructor.

Stable:
ICU 55

Member Function Documentation

Returns a copy of this object.

Caller must free returned copy.

Stable:
ICU 55

Definition at line 121 of file scientificnumberformatter.h.

static ScientificNumberFormatter* icu::ScientificNumberFormatter::createMarkupInstance ( DecimalFormat fmtToAdopt,
const UnicodeString beginMarkup,
const UnicodeString endMarkup,
UErrorCode status 
) [static]

Creates a ScientificNumberFormatter instance that uses markup for exponents.

Parameters:
fmtToAdoptThe DecimalFormat which must be configured for scientific notation.
beginMarkupthe markup to start superscript.
endMarkupthe markup to end superscript.
statuserror returned here.
Returns:
The new ScientificNumberFormatter instance.
Stable:
ICU 55
static ScientificNumberFormatter* icu::ScientificNumberFormatter::createMarkupInstance ( const Locale locale,
const UnicodeString beginMarkup,
const UnicodeString endMarkup,
UErrorCode status 
) [static]

Creates a ScientificNumberFormatter instance that uses markup for exponents for this locale.

Parameters:
localeThe locale
beginMarkupthe markup to start superscript.
endMarkupthe markup to end superscript.
statuserror returned here.
Returns:
The ScientificNumberFormatter instance.
Stable:
ICU 55

Creates a ScientificNumberFormatter instance that uses superscript characters for exponents.

Parameters:
fmtToAdoptThe DecimalFormat which must be configured for scientific notation.
statuserror returned here.
Returns:
The new ScientificNumberFormatter instance.
Stable:
ICU 55

Creates a ScientificNumberFormatter instance that uses superscript characters for exponents for this locale.

Parameters:
localeThe locale
statuserror returned here.
Returns:
The ScientificNumberFormatter instance.
Stable:
ICU 55
UnicodeString& icu::ScientificNumberFormatter::format ( const Formattable number,
UnicodeString appendTo,
UErrorCode status 
) const

Formats a number into user friendly scientific notation.

Parameters:
numberthe number to format.
appendToformatted string appended here.
statusany error returned here.
Returns:
appendTo
Stable:
ICU 55

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