Top Description Inners Fields Constructors Methods
com.ibm.icu.text

public final Class ScientificNumberFormatter

extends Object
Class Inheritance
Imports
java.text.AttributedCharacterIterator, .AttributedCharacterIterator.Attribute, .CharacterIterator, java.util.Map, com.ibm.icu.impl.StaticUnicodeSets, com.ibm.icu.lang.UCharacter, com.ibm.icu.util.ULocale

A formatter that formats numbers in user-friendly scientific notation. ScientificNumberFormatter instances are immutable and thread-safe. Sample code:
ULocale en = new ULocale("en");
ScientificNumberFormatter fmt = ScientificNumberFormatter.getMarkupInstance(
        en, "<sup>", "</sup>");
// Output: "1.23456×10<sup>-78</sup>"
System.out.println(fmt.format(1.23456e-78));
ICU Status
Stable since ICU 55.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private abstract static class
ScientificNumberFormatter.Style

A style type for ScientificNumberFormatter.

private static class

Field Summary

Modifier and TypeField and Description
private final DecimalFormat
private final String
private final ScientificNumberFormatter.Style
private static final ScientificNumberFormatter.Style

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the formatted string.
format
(Object
Can be a double, int, Number or anything that DecimalFormat#format(Object) accepts.
number
)

Formats a number

private static ScientificNumberFormatter
private static ScientificNumberFormatter
public static ScientificNumberFormatter

Returns:

The ScientificNumberFormatter instance.
getMarkupInstance
(ULocale
The locale
locale
,
String
the markup to start superscript e.g <sup>
beginMarkup
,
String
the markup to end superscript e.g </sup>
endMarkup
)

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

public static ScientificNumberFormatter

Returns:

The ScientificNumberFormatter instance.
getMarkupInstance
(DecimalFormat
The DecimalFormat must be configured for scientific notation. Caller may safely change df after this call as this method clones it when creating the ScientificNumberFormatter.
df
,
String
the markup to start superscript e.g <sup>
beginMarkup
,
String
the markup to end superscript e.g </sup>
endMarkup
)

Gets a ScientificNumberFormatter instance that uses markup for exponents.

private static String
public static ScientificNumberFormatter

Returns:

The ScientificNumberFormatter instance.
getSuperscriptInstance
(ULocale
The locale
locale
)

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

public static ScientificNumberFormatter

Returns:

the ScientificNumberFormatter instance.
getSuperscriptInstance
(DecimalFormat
The DecimalFormat must be configured for scientific notation. Caller may safely change df after this call as this method clones it when creating the ScientificNumberFormatter.
df
)

Gets a ScientificNumberFormatter instance that uses superscript characters for exponents.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

fmtback to summary
private final DecimalFormat fmt
preExponentback to summary
private final String preExponent
styleback to summary
private final ScientificNumberFormatter.Style style
SUPER_SCRIPTback to summary
private static final ScientificNumberFormatter.Style SUPER_SCRIPT

Constructor Detail

ScientificNumberFormatterback to summary
private ScientificNumberFormatter(DecimalFormat decimalFormat, String preExponent, ScientificNumberFormatter.Style style)

Method Detail

formatback to summary
public String format(Object number)

Formats a number

Parameters
number:Object

Can be a double, int, Number or anything that DecimalFormat#format(Object) accepts.

Returns:String

the formatted string.

ICU Status
Stable since ICU 55.
getInstanceback to summary
private static ScientificNumberFormatter getInstance(DecimalFormat decimalFormat, ScientificNumberFormatter.Style style)
getInstanceForLocaleback to summary
private static ScientificNumberFormatter getInstanceForLocale(ULocale locale, ScientificNumberFormatter.Style style)
getMarkupInstanceback to summary
public static ScientificNumberFormatter getMarkupInstance(ULocale locale, String beginMarkup, String endMarkup)

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

Parameters
locale:ULocale

The locale

beginMarkup:String

the markup to start superscript e.g <sup>

endMarkup:String

the markup to end superscript e.g </sup>

Returns:ScientificNumberFormatter

The ScientificNumberFormatter instance.

ICU Status
Stable since ICU 55.
getMarkupInstanceback to summary
public static ScientificNumberFormatter getMarkupInstance(DecimalFormat df, String beginMarkup, String endMarkup)

Gets a ScientificNumberFormatter instance that uses markup for exponents.

Parameters
df:DecimalFormat

The DecimalFormat must be configured for scientific notation. Caller may safely change df after this call as this method clones it when creating the ScientificNumberFormatter.

beginMarkup:String

the markup to start superscript e.g <sup>

endMarkup:String

the markup to end superscript e.g </sup>

Returns:ScientificNumberFormatter

The ScientificNumberFormatter instance.

ICU Status
Stable since ICU 55.
getPreExponentback to summary
private static String getPreExponent(DecimalFormatSymbols dfs)
getSuperscriptInstanceback to summary
public static ScientificNumberFormatter getSuperscriptInstance(ULocale locale)

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

Parameters
locale:ULocale

The locale

Returns:ScientificNumberFormatter

The ScientificNumberFormatter instance.

ICU Status
Stable since ICU 55.
getSuperscriptInstanceback to summary
public static ScientificNumberFormatter getSuperscriptInstance(DecimalFormat df)

Gets a ScientificNumberFormatter instance that uses superscript characters for exponents.

Parameters
df:DecimalFormat

The DecimalFormat must be configured for scientific notation. Caller may safely change df after this call as this method clones it when creating the ScientificNumberFormatter.

Returns:ScientificNumberFormatter

the ScientificNumberFormatter instance.

ICU Status
Stable since ICU 55.
com.ibm.icu.text back to summary

private Class ScientificNumberFormatter.MarkupStyle

extends Style
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final String
private final String

Constructor Summary

AccessConstructor and Description
pack-priv
MarkupStyle(String beginMarkup, String endMarkup)

Method Summary

Modifier and TypeMethod and Description
pack-priv String
Inherited from com.ibm.icu.text.ScientificNumberFormatter.Style:
append

Field Detail

beginMarkupback to summary
private final String beginMarkup
endMarkupback to summary
private final String endMarkup

Constructor Detail

MarkupStyleback to summary
pack-priv MarkupStyle(String beginMarkup, String endMarkup)

Method Detail

formatback to summary
pack-priv String format(AttributedCharacterIterator iterator, String preExponent)

Implements abstract com.ibm.icu.text.ScientificNumberFormatter.Style.format.

Annotations
@Override
com.ibm.icu.text back to summary

private abstract Class ScientificNumberFormatter.Style

extends Object
Class Inheritance
Known Direct Subclasses
com.ibm.icu.text.ScientificNumberFormatter.MarkupStyle, com.ibm.icu.text.ScientificNumberFormatter.SuperscriptStyle

A style type for ScientificNumberFormatter. All Style instances are immutable and thread-safe.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static void
append(AttributedCharacterIterator iterator, int start, int limit, StringBuilder result)

pack-priv abstract String
format(AttributedCharacterIterator iterator, String preExponent)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Styleback to summary
private Style()

Method Detail

appendback to summary
pack-priv static void append(AttributedCharacterIterator iterator, int start, int limit, StringBuilder result)
formatback to summary
pack-priv abstract String format(AttributedCharacterIterator iterator, String preExponent)
com.ibm.icu.text back to summary

private Class ScientificNumberFormatter.SuperscriptStyle

extends Style
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final char[]
private static final char
private static final char

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static int
private static void
copyAsSuperscript(AttributedCharacterIterator iterator, int start, int limit, StringBuilder result)

pack-priv String
Inherited from com.ibm.icu.text.ScientificNumberFormatter.Style:
append

Field Detail

SUPERSCRIPT_DIGITSback to summary
private static final char[] SUPERSCRIPT_DIGITS
SUPERSCRIPT_MINUS_SIGNback to summary
private static final char SUPERSCRIPT_MINUS_SIGN
SUPERSCRIPT_PLUS_SIGNback to summary
private static final char SUPERSCRIPT_PLUS_SIGN

Constructor Detail

SuperscriptStyleback to summary
private SuperscriptStyle()

Method Detail

char32AtAndAdvanceback to summary
private static int char32AtAndAdvance(AttributedCharacterIterator iterator)
copyAsSuperscriptback to summary
private static void copyAsSuperscript(AttributedCharacterIterator iterator, int start, int limit, StringBuilder result)
formatback to summary
pack-priv String format(AttributedCharacterIterator iterator, String preExponent)

Implements abstract com.ibm.icu.text.ScientificNumberFormatter.Style.format.

Annotations
@Override