All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.roguewave.format.NumericFormat

java.lang.Object
   |
   +----com.roguewave.format.NumericFormat

public class NumericFormat
extends Object
implements Cloneable
An output format specification and formatter class.

The NumericFormat class provides a flexible mechanism to control the format of numeric values. The precision to use, how the sign should be displayed, field width, left and right padding characters, and other attributes can all be controlled using the NumericFormat class.

AttributeTypeDefaultDescription
decimalSymbol String "." the string to print at the decimal point
precision int 4 the number of digits after the decimal place
width int 0 if the formatted number is less than this width it will be padded to this width
leftPadChar char <space> the char to use when padding to the left of the number
rightPadChar char <space> the char to use when padding to the right of the number
parenthesesForNegative boolean false indicate negative numbers by enclosing them in parentheses ()
positiveSymbol String "" the string to use to indicate a positive number
leftSignNear boolean true if the sign is to be on the left side should it appear before (false) or after (true) left side padding, if any
rightSignNear boolean true if the sign is to be on the right side should it appear before (true) or after (false) right side padding, if any
signOnLeft boolean true should the sign be displayed to the left (true) or right (false) of the number
roundingMethod int 0 the rounding method to be used when asking a Formattable object to decrease the number of digits. (Java-supplied numeric types use Math.round(n) for rounding.)
preExponent String "e" the string to be printed before the exponent when using scientific notation
postExponent String "" the string to be printed after the exponent when using scientific notation
addLeadingZero boolean false if there are no digits before the decimal place put a 0 there.
addTrailingZero boolean false if there are no digits after the decimal place put a 0 there
showDecimalOnInteger boolean false if the number has an integer value still show the decimal
useDefaultPrecision boolean true produce trailing digits similar to what would be produced by the type's toString() method.

See NumericFormatExample.java in the examples directory.


Constructor Index

 o NumericFormat()
Use the default precision of 4 digits after the decimal place.
 o NumericFormat(int)
Use the specified precision.

Method Index

 o addLeadingZero()
Return whether or not a leading '0' should be added to numbers with no digits before the decimal place.
 o addTrailingZero()
Return whether a trailing zero will be added to integer valued numbers.
 o clone()
Returns a clone of this NumericFormat object.
 o format(boolean, String, String)
Output the argument value formatted as specified by self.
 o format(Double)
Produce a nicely formatted String representation of the argument.
 o format(double)
Produce a nicely formatted String representation of the argument.
 o format(Float)
Produce a nicely formatted String representation of the argument.
 o format(float)
Produce a nicely formatted String representation of the argument.
 o format(Formattable)
Produce a nicely formatted String representation of the argument.
 o format(int)
Produce a nicely formatted String representation of the argument.
 o format(Integer)
Produce a nicely formatted String representation of the argument.
 o format(long)
Produce a nicely formatted String representation of the argument.
 o format(Long)
Produce a nicely formatted String representation of the argument.
 o getDecimalPosition()
Return the position within the field at which the decimal symbol should occur.
 o getDecimalSymbol()
Return the string used to represent the decimal place.
 o getPositiveSymbol()
Return the string that will be used for a positive sign.
 o getPostExponent()
Return the string that is printed after the exponent when using scientific notation.
 o getPrecision()
Get the current precision setting.
 o getPreExponent()
Return the string that is printed before the exponent when using scientific notation.
 o getRoundingMethod()
Return the rounding method used when reducing the number of digits for numbers that implement the Formattable interface.
 o getWidth()
Get the current setting for width
 o leftSignNear()
Return whether a sign on the left side should appear next to the numeral or at the left of the field.
 o parenthesesForNegative()
Return whether parentheses will be used to denote negative numbers.
 o rightSignNear()
Return whether a sign on the right side should appear next to the numeral or at the right of the field.
 o scientificFormat(boolean, String, String)
Format the number using scientific notation.
 o setAddLeadingZero(boolean)
Specify whether a leading '0' should be prepended to numbers with no digits before the decimal place.
 o setAddTrailingZero(boolean)
Set whether a trailing zero will be added to integer valued numbers.
 o setDecimalPosition(int)
Set the position within the field at which the decimal symbol should occur.
 o setDecimalSymbol(String)
Set the string used to represent the decimal place, default is "."
 o setLeftPadChar(char)
Set the char that will be used to pad on the left hand side.
 o setLeftSignNear(boolean)
If the sign is to appear on the left side and left side padding is to be performed, should the sign be next to the numeric value or to the left of the padding.
 o setParenthesesForNegative(boolean)
Set whether or not parentheses will be used for negative numbers.
 o setPositiveSymbol(String)
Set the string that will be used for a positive sign.
 o setPostExponent(String)
Set the string that is printed after the exponent when using scientific notation.
 o setPrecision(int)
Set the precision (number of digits after the decimal point).
 o setPreExponent(String)
Set the string that is printed before the exponent when using scientific notation.
 o setRightPadChar(char)
Set the char that will be used to pad on the right hand side.
 o setRightSignNear(boolean)
If the sign is to appear on the right side and right side padding is to be performed, should the sign be next to the numeric value or to the right of the padding.
 o setRoundingMethod(int)
Set the rounding method to be used when decreasing the number of digits for numbers that implement the Formattable interface.
 o setShowDecimalOnInteger(boolean)
Set whether the decimal symbol should be shown on integer valued floating point numbers.
 o setSignOnLeft(boolean)
Set which side the sign should appear on, true for left, false for right.
 o setUseDefaultPrecision(boolean)
Set whether default precision should be used.
 o setWidth(int)
Set the field width
 o showDecimalOnInteger()
Return whether the decimal symbol will be shown on integer valued floating point values.
 o signOnLeft()
Return whether the sign is to appear to the left of the numeric value.
 o simpleFormat(Formattable)
simpleFormat uses a subset of the format variables to produce a string of the form [-]ddd.ddd which can be laid out with the NumericPicture class.
 o useDefaultPrecision()
Return whether default precision will be used.

Constructors

 o NumericFormat
 public NumericFormat()
Use the default precision of 4 digits after the decimal place.

 o NumericFormat
 public NumericFormat(int precision)
Use the specified precision.

Methods

 o clone
 public Object clone()
Returns a clone of this NumericFormat object.

Overrides:
clone in class Object
 o getPrecision
 public int getPrecision()
Get the current precision setting.

 o setPrecision
 public void setPrecision(int precision)
Set the precision (number of digits after the decimal point). Also sets useDefaultPrecision to false.

 o getWidth
 public int getWidth()
Get the current setting for width

 o setWidth
 public void setWidth(int width)
Set the field width

 o getDecimalSymbol
 public String getDecimalSymbol()
Return the string used to represent the decimal place.

 o setDecimalSymbol
 public void setDecimalSymbol(String decimalSymbol)
Set the string used to represent the decimal place, default is "."

 o setLeftPadChar
 public void setLeftPadChar(char c)
Set the char that will be used to pad on the left hand side. The default is ' ' (space).

 o setRightPadChar
 public void setRightPadChar(char c)
Set the char that will be used to pad on the right hand side. The default is '0' (zero).

 o setLeftSignNear
 public void setLeftSignNear(boolean value)
If the sign is to appear on the left side and left side padding is to be performed, should the sign be next to the numeric value or to the left of the padding.

 o leftSignNear
 public boolean leftSignNear()
Return whether a sign on the left side should appear next to the numeral or at the left of the field.

 o rightSignNear
 public boolean rightSignNear()
Return whether a sign on the right side should appear next to the numeral or at the right of the field.

 o setRightSignNear
 public void setRightSignNear(boolean value)
If the sign is to appear on the right side and right side padding is to be performed, should the sign be next to the numeric value or to the right of the padding.

 o signOnLeft
 public boolean signOnLeft()
Return whether the sign is to appear to the left of the numeric value.

 o setSignOnLeft
 public void setSignOnLeft(boolean signOnLeft)
Set which side the sign should appear on, true for left, false for right.

 o getPositiveSymbol
 public String getPositiveSymbol()
Return the string that will be used for a positive sign.

 o setPositiveSymbol
 public void setPositiveSymbol(String positiveSymbol)
Set the string that will be used for a positive sign.

 o parenthesesForNegative
 public boolean parenthesesForNegative()
Return whether parentheses will be used to denote negative numbers.

 o setParenthesesForNegative
 public void setParenthesesForNegative(boolean parenthesesForNegative)
Set whether or not parentheses will be used for negative numbers.

 o getRoundingMethod
 public int getRoundingMethod()
Return the rounding method used when reducing the number of digits for numbers that implement the Formattable interface.

 o setRoundingMethod
 public void setRoundingMethod(int roundingMethod)
Set the rounding method to be used when decreasing the number of digits for numbers that implement the Formattable interface.

 o getDecimalPosition
 public int getDecimalPosition()
Return the position within the field at which the decimal symbol should occur.

 o setDecimalPosition
 public void setDecimalPosition(int decimalPosition)
Set the position within the field at which the decimal symbol should occur. Force the width to be wide enough to accommodate this.

 o getPreExponent
 public String getPreExponent()
Return the string that is printed before the exponent when using scientific notation.

 o setPreExponent
 public void setPreExponent(String preExponent)
Set the string that is printed before the exponent when using scientific notation.

 o getPostExponent
 public String getPostExponent()
Return the string that is printed after the exponent when using scientific notation.

 o setPostExponent
 public void setPostExponent(String postExponent)
Set the string that is printed after the exponent when using scientific notation.

 o addLeadingZero
 public boolean addLeadingZero()
Return whether or not a leading '0' should be added to numbers with no digits before the decimal place.

 o setAddLeadingZero
 public void setAddLeadingZero(boolean addLeadingZero)
Specify whether a leading '0' should be prepended to numbers with no digits before the decimal place.

 o addTrailingZero
 public boolean addTrailingZero()
Return whether a trailing zero will be added to integer valued numbers.

 o setAddTrailingZero
 public void setAddTrailingZero(boolean addTrailingZero)
Set whether a trailing zero will be added to integer valued numbers.

 o showDecimalOnInteger
 public boolean showDecimalOnInteger()
Return whether the decimal symbol will be shown on integer valued floating point values.

 o setShowDecimalOnInteger
 public void setShowDecimalOnInteger(boolean showDecimalOnInteger)
Set whether the decimal symbol should be shown on integer valued floating point numbers.

 o useDefaultPrecision
 public boolean useDefaultPrecision()
Return whether default precision will be used.

 o setUseDefaultPrecision
 public void setUseDefaultPrecision(boolean useDefaultPrecision)
Set whether default precision should be used.

 o simpleFormat
 public String simpleFormat(Formattable form)
simpleFormat uses a subset of the format variables to produce a string of the form [-]ddd.ddd which can be laid out with the NumericPicture class.

 o format
 public String format(Formattable form)
Produce a nicely formatted String representation of the argument.

 o format
 public String format(int i)
Produce a nicely formatted String representation of the argument.

 o format
 public String format(Integer i)
Produce a nicely formatted String representation of the argument.

 o format
 public String format(long l)
Produce a nicely formatted String representation of the argument.

 o format
 public String format(Long l)
Produce a nicely formatted String representation of the argument.

 o format
 public String format(float f)
Produce a nicely formatted String representation of the argument.

 o format
 public String format(Float f)
Produce a nicely formatted String representation of the argument.

 o format
 public String format(double d)
Produce a nicely formatted String representation of the argument.

 o format
 public String format(Double d)
Produce a nicely formatted String representation of the argument.

 o format
 public String format(boolean isPositive,
                      String leading,
                      String trailing)
Output the argument value formatted as specified by self.

 o scientificFormat
 public String scientificFormat(boolean isPositive,
                                String leading,
                                String trailing)
Format the number using scientific notation.


All Packages  Class Hierarchy  This Package  Previous  Next  Index