23.07.2013 Views

Java IO.pdf - Nguyen Dang Binh

Java IO.pdf - Nguyen Dang Binh

Java IO.pdf - Nguyen Dang Binh

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

**<br />

* Concrete class for formatting large and small numbers, allowing a<br />

variety<br />

* of exponential/scientific notation<br />

* @see java.util.Format<br />

* @see java.text.NumberFormat<br />

* @version 1.0 25 Jan 1998<br />

* @author Elliotte Rusty Harold<br />

*/<br />

public class ExponentialFormat extends NumberFormat {<br />

// might make this only a number format<br />

DecimalFormatSymbols symbols;<br />

DecimalFormat parser;<br />

public ExponentialFormat() {<br />

this(new DecimalFormat());<br />

}<br />

/**<br />

* Create an ExponentialFormat from the given format and the symbols<br />

* for the default locale.<br />

* <br />

* @param format The decimal format that parses the parts of the<br />

exponential.<br />

*/<br />

public ExponentialFormat(DecimalFormat format) {<br />

this.parser = format;<br />

this.symbols = format.getDecimalFormatSymbols();<br />

this.parser.setGroupingUsed(false);<br />

}<br />

public StringBuffer format(double number, StringBuffer toAppendTo,<br />

FieldPosition pos) {<br />

if (Double.isNaN(number)) {<br />

toAppendTo.append(symbols.getNaN());<br />

}<br />

else if (number < 0) {<br />

toAppendTo.append(symbols.getMinusSign());<br />

number = -number;<br />

}<br />

// Now we just have to format a nonnegative number.<br />

if (Double.isInfinite(number)) {<br />

toAppendTo.append(symbols.getInfinity());<br />

}<br />

else {<br />

int maxFractionDigits = this.getMaximumFractionDigits();<br />

if (maxFractionDigits

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!