public final class ScientificFormatHelper extends Object
DecimalFormat decfmt = (DecimalFormat) NumberFormat.getScientificInstance(new ULocale("en")); AttributedCharacterIterator iterator = decfmt.formatToCharacterIterator(1.23456e-78); ScientificFormatHelper helper = ScientificFormatHelper.getInstance( decfmt.getDecimalFormatSymbols());// Output: "1.23456×10-78" System.out.println(helper.insertMarkup(iterator, "", ""));
NumberFormat
Modifier and Type | Method and Description |
---|---|
static ScientificFormatHelper |
getInstance(DecimalFormatSymbols dfs)
Returns a new ScientificFormatHelper.
|
String |
insertMarkup(AttributedCharacterIterator iterator,
CharSequence beginMarkup,
CharSequence endMarkup)
Makes scientific notation user-friendly by surrounding exponent with
html to make it superscript.
|
String |
toSuperscriptExponentDigits(AttributedCharacterIterator iterator)
Makes scientific notation user-friendly by using specific code points
for superscript 0..9, -, and + in the exponent rather than by using
html.
|
public static ScientificFormatHelper getInstance(DecimalFormatSymbols dfs)
dfs
- comes from the DecimalFormat instance used for default scientific notation.public String insertMarkup(AttributedCharacterIterator iterator, CharSequence beginMarkup, CharSequence endMarkup)
iterator
- the value that DecimalFormat.formatToCharacterIterator() returned.beginMarkup
- the start html for the exponent e.g ""endMarkup
- the end html for the exponent e.g ""public String toSuperscriptExponentDigits(AttributedCharacterIterator iterator)
iterator
- the value that DecimalFormat.formatToCharacterIterator() returned.Copyright (c) 2014 IBM Corporation and others.