FreeHEP API
Version current

org.freehep.util
Class ScientificFormat

java.lang.Object
  extended byjava.text.Format
      extended byorg.freehep.util.ScientificFormat
All Implemented Interfaces:
Cloneable, Serializable

public class ScientificFormat
extends Format

This code formats numbers in Scientific Notation. The input Number object is returned as a ScientificFormated string. There are two output styles: Pure and Standard scientific notation. Pure formatted numbers have precisely the number of digits specified by the significant digits (sigDig) parameter and always specify a Base 10 Exponential(E). Standard formated numbers have the number of digits specified by the significant digits (sigDig) parameter but will not have a Base 10 Exponential(E) if the number of digits in the mantissa <= maxWidth.

Version:
$Id: ScientificFormat.java,v 1.4 2004/12/30 08:35:07 tonyj Exp $
Author:
Paul Spence, Mark Donszelmann
See Also:
Serialized Form
Source Code:
ScientificFormat.java

Nested Class Summary
 
Nested classes inherited from class java.text.Format
Format.Field
 
Constructor Summary
ScientificFormat()
           
ScientificFormat(int sigDigit, int maxWidth, boolean SciNote)
          Sets the significant digits, maximum allowable width and number formatting style (SciNote == true for Pure formatting).
 
Method Summary
 String format(double d)
          Format the number using scientific notation
 StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos)
          Implementation of inherited abstract method.
 int getMaxWidth()
          Returns the maximum allowable width of formatted number excluding any exponentials
 boolean getScientificNotationStyle()
          Returns the formatting style: True means Pure scientific formatting, False means standard.
 int getSigDigits()
          Returns the number of significant digits
 Object parseObject(String source, ParsePosition pos)
          Dummy implementation of inherited abstract method.
 void setMaxWidth(int mWidth)
          Sets the maximum allowable length of the formattted number mantissa before exponential notation is used.
 void setScientificNotationStyle(boolean sciNote)
          Sets the format style used.
 void setSigDigits(int SigDigit)
          Sets the number of significant digits for the formatted number
 
Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScientificFormat

public ScientificFormat()

ScientificFormat

public ScientificFormat(int sigDigit,
                        int maxWidth,
                        boolean SciNote)
Sets the significant digits, maximum allowable width and number formatting style (SciNote == true for Pure formatting).

Method Detail

format

public StringBuffer format(Object obj,
                           StringBuffer toAppendTo,
                           FieldPosition pos)
Implementation of inherited abstract method. Checks to see if object to be formatted is of type Number. If so casts the Number object to double and calls the format method. Returns the result.


parseObject

public Object parseObject(String source,
                          ParsePosition pos)
Dummy implementation of inherited abstract method.


getSigDigits

public int getSigDigits()
Returns the number of significant digits


getMaxWidth

public int getMaxWidth()
Returns the maximum allowable width of formatted number excluding any exponentials


getScientificNotationStyle

public boolean getScientificNotationStyle()
Returns the formatting style: True means Pure scientific formatting, False means standard.


setSigDigits

public void setSigDigits(int SigDigit)
Sets the number of significant digits for the formatted number


setMaxWidth

public void setMaxWidth(int mWidth)
Sets the maximum allowable length of the formattted number mantissa before exponential notation is used.


setScientificNotationStyle

public void setScientificNotationStyle(boolean sciNote)
Sets the format style used. There are two output styles: Pure and Standard scientific notation. Pure formatted numbers have precisely the number of digits specified by the significant digits (sigDig) parameter and always specify a Base 10 Exponential(E). Standard formated numbers have the number of digits specified by the significant digits (sigDig) parameter but will not have a Base 10 Exponential(E) if the number of digits in the mantissa <= maxWidth.


format

public String format(double d)
Format the number using scientific notation


FreeHEP API
Version current

Copyright © 2000-2004 FreeHEP, All Rights Reserved.