ICU 54.1
54.1
|
A helper class for formatting numbers in standard scientific notation instead of E notation. More...
#include <scientificformathelper.h>
Public Member Functions | |
ScientificFormatHelper (const DecimalFormatSymbols &symbols, UErrorCode &status) | |
Constructor. More... | |
ScientificFormatHelper (const ScientificFormatHelper &other) | |
Copy constructor. More... | |
ScientificFormatHelper & | operator= (const ScientificFormatHelper &other) |
Assignment operator. More... | |
virtual | ~ScientificFormatHelper () |
Destructor. More... | |
UnicodeString & | 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. More... | |
UnicodeString & | toSuperscriptExponentDigits (const UnicodeString &s, FieldPositionIterator &fpi, UnicodeString &result, UErrorCode &status) const |
Formats standard scientific notation by using superscript unicode points 0..9. More... | |
![]() | |
virtual | ~UObject () |
Destructor. More... | |
virtual UClassID | getDynamicClassID () const |
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class. More... | |
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));
Definition at line 51 of file scientificformathelper.h.
icu::ScientificFormatHelper::ScientificFormatHelper | ( | const DecimalFormatSymbols & | symbols, |
UErrorCode & | status | ||
) |
Constructor.
symbols | comes from DecimalFormat instance used for default scientific notation. |
status | any error reported here. |
icu::ScientificFormatHelper::ScientificFormatHelper | ( | const ScientificFormatHelper & | other | ) |
Copy constructor.
|
virtual |
Destructor.
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.
s | the original formatted scientific notation e.g "6.02e23". s is output from NumberFormat::createScientificInstance()->format(). |
fpi | the FieldPositionIterator from the format call. fpi is output from NumberFormat::createScientificInstance()->format(). |
beginMarkup | the start html for the exponent e.g "<sup>" |
endMarkup | the end html for the exponent e.g "</sup>" |
result | standard scientific notation appended here. |
status | any 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. |
ScientificFormatHelper& icu::ScientificFormatHelper::operator= | ( | const ScientificFormatHelper & | other | ) |
Assignment operator.
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.
s | the original formatted scientific notation e.g "6.02e23". s is output from NumberFormat::createScientificInstance()->format(). |
fpi | the FieldPositionIterator from the format call. fpi is output from NumberFormat::createScientificInstance()->format(). |
result | standard scientific notation appended here. |
status | any 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. |