ICU 54.1  54.1
Public Member Functions
icu::ScientificFormatHelper Class Reference

A helper class for formatting numbers in standard scientific notation instead of E notation. More...

#include <scientificformathelper.h>

Inheritance diagram for icu::ScientificFormatHelper:
icu::UObject icu::UMemory

Public Member Functions

 ScientificFormatHelper (const DecimalFormatSymbols &symbols, UErrorCode &status)
 Constructor. More...
 
 ScientificFormatHelper (const ScientificFormatHelper &other)
 Copy constructor. More...
 
ScientificFormatHelperoperator= (const ScientificFormatHelper &other)
 Assignment operator. More...
 
virtual ~ScientificFormatHelper ()
 Destructor. More...
 
UnicodeStringinsertMarkup (const UnicodeString &s, FieldPositionIterator &fpi, const UnicodeString &beginMarkup, const UnicodeString &endMarkup, UnicodeString &result, UErrorCode &status) const
 Formats standard scientific notation by surrounding exponent with html to make it superscript. More...
 
UnicodeStringtoSuperscriptExponentDigits (const UnicodeString &s, FieldPositionIterator &fpi, UnicodeString &result, UErrorCode &status) const
 Formats standard scientific notation by using superscript unicode points 0..9. More...
 
- Public Member Functions inherited from icu::UObject
virtual ~UObject ()
 Destructor. More...
 
virtual UClassID getDynamicClassID () const
 ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class. More...
 

Detailed Description

A helper class for formatting numbers in standard scientific notation instead of E notation.

Sample code:

UErrorCode status = U_ZERO_ERROR;
DecimalFormat *decfmt = (DecimalFormat *)
    NumberFormat::createScientificInstance("en", status);
UnicodeString appendTo;
FieldPositionIterator fpositer;
decfmt->format(1.23456e-78, appendTo, &fpositer, status);
ScientificFormatHelper helper(*decfmt->getDecimalFormatSymbols(), status);
UnicodeString result;
// result = "1.23456x10<sup>-78</sup>"
helper.insertMarkup(appendTo, fpositer, "<sup>", "</sup>", result, status));
See Also
NumberFormat
Draft:
This API may be changed in the future versions and was introduced in ICU 54

Definition at line 51 of file scientificformathelper.h.

Constructor & Destructor Documentation

icu::ScientificFormatHelper::ScientificFormatHelper ( const DecimalFormatSymbols symbols,
UErrorCode status 
)

Constructor.

Parameters
symbolscomes from DecimalFormat instance used for default scientific notation.
statusany error reported here.
Draft:
This API may be changed in the future versions and was introduced in ICU 54
icu::ScientificFormatHelper::ScientificFormatHelper ( const ScientificFormatHelper other)

Copy constructor.

Draft:
This API may be changed in the future versions and was introduced in ICU 54
virtual icu::ScientificFormatHelper::~ScientificFormatHelper ( )
virtual

Destructor.

Draft:
This API may be changed in the future versions and was introduced in ICU 54

Member Function Documentation

UnicodeString& icu::ScientificFormatHelper::insertMarkup ( const UnicodeString s,
FieldPositionIterator fpi,
const UnicodeString beginMarkup,
const UnicodeString endMarkup,
UnicodeString result,
UErrorCode status 
) const

Formats standard scientific notation by surrounding exponent with html to make it superscript.

Parameters
sthe original formatted scientific notation e.g "6.02e23". s is output from NumberFormat::createScientificInstance()->format().
fpithe FieldPositionIterator from the format call. fpi is output from NumberFormat::createScientificInstance()->format().
beginMarkupthe start html for the exponent e.g "<sup>"
endMarkupthe end html for the exponent e.g "</sup>"
resultstandard scientific notation appended here.
statusany error returned here. When status is set to a non-zero error, the value of result is unspecified, and client should fallback to using s for scientific notation.
Returns
the value stored in result.
Draft:
This API may be changed in the future versions and was introduced in ICU 54
ScientificFormatHelper& icu::ScientificFormatHelper::operator= ( const ScientificFormatHelper other)

Assignment operator.

Draft:
This API may be changed in the future versions and was introduced in ICU 54
UnicodeString& icu::ScientificFormatHelper::toSuperscriptExponentDigits ( const UnicodeString s,
FieldPositionIterator fpi,
UnicodeString result,
UErrorCode status 
) const

Formats standard scientific notation by using superscript unicode points 0..9.

Parameters
sthe original formatted scientific notation e.g "6.02e23". s is output from NumberFormat::createScientificInstance()->format().
fpithe FieldPositionIterator from the format call. fpi is output from NumberFormat::createScientificInstance()->format().
resultstandard scientific notation appended here.
statusany error returned here. When status is set to a non-zero error, the value of result is unspecified, and client should fallback to using s for scientific notation.
Returns
the value stored in result.
Draft:
This API may be changed in the future versions and was introduced in ICU 54

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