public final class ScientificFormatHelper
extends java.lang.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.
|
java.lang.String |
insertMarkup(java.text.AttributedCharacterIterator iterator,
java.lang.CharSequence beginMarkup,
java.lang.CharSequence endMarkup)
Makes scientific notation user-friendly by surrounding exponent with
html to make it superscript.
|
java.lang.String |
toSuperscriptExponentDigits(java.text.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 java.lang.String insertMarkup(java.text.AttributedCharacterIterator iterator, java.lang.CharSequence beginMarkup, java.lang.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 java.lang.String toSuperscriptExponentDigits(java.text.AttributedCharacterIterator iterator)
iterator
- the value that DecimalFormat.formatToCharacterIterator() returned.Copyright (c) 2014 IBM Corporation and others.