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.
Attribute | Type | Default | Description |
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.
-
NumericFormat()
- Use the default precision of 4 digits after the decimal place.
-
NumericFormat(int)
- Use the specified precision.
-
addLeadingZero()
- Return whether or not a leading '0' should be added to numbers
with no digits before the decimal place.
-
addTrailingZero()
- Return whether a trailing zero will be added to integer valued numbers.
-
clone()
- Returns a clone of this NumericFormat object.
-
format(boolean, String, String)
- Output the argument value formatted as specified by self.
-
format(Double)
- Produce a nicely formatted String representation of the argument.
-
format(double)
- Produce a nicely formatted String representation of the argument.
-
format(Float)
- Produce a nicely formatted String representation of the argument.
-
format(float)
- Produce a nicely formatted String representation of the argument.
-
format(Formattable)
- Produce a nicely formatted String representation of the argument.
-
format(int)
- Produce a nicely formatted String representation of the argument.
-
format(Integer)
- Produce a nicely formatted String representation of the argument.
-
format(long)
- Produce a nicely formatted String representation of the argument.
-
format(Long)
- Produce a nicely formatted String representation of the argument.
-
getDecimalPosition()
- Return the position within the field
at which the decimal symbol should occur.
-
getDecimalSymbol()
- Return the string used to represent the decimal place.
-
getPositiveSymbol()
- Return the string that will be used for a positive sign.
-
getPostExponent()
- Return the string that is printed after the exponent when using
scientific notation.
-
getPrecision()
- Get the current precision setting.
-
getPreExponent()
- Return the string that is printed before the exponent when using
scientific notation.
-
getRoundingMethod()
- Return the rounding method used when reducing the number of digits
for numbers that implement the Formattable interface.
-
getWidth()
- Get the current setting for width
-
leftSignNear()
- Return whether a sign on the left side should appear next to the
numeral or at the left of the field.
-
parenthesesForNegative()
- Return whether parentheses will be used to denote negative numbers.
-
rightSignNear()
- Return whether a sign on the right side should appear next to the
numeral or at the right of the field.
-
scientificFormat(boolean, String, String)
- Format the number using scientific notation.
-
setAddLeadingZero(boolean)
- Specify whether a leading '0' should be prepended to numbers
with no digits before the decimal place.
-
setAddTrailingZero(boolean)
- Set whether a trailing zero will be added to integer valued numbers.
-
setDecimalPosition(int)
- Set the position within the field
at which the decimal symbol should occur.
-
setDecimalSymbol(String)
- Set the string used to represent the decimal place, default is "."
-
setLeftPadChar(char)
- Set the char that will be used to pad on the left hand side.
-
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.
-
setParenthesesForNegative(boolean)
- Set whether or not parentheses will be used for negative numbers.
-
setPositiveSymbol(String)
- Set the string that will be used for a positive sign.
-
setPostExponent(String)
- Set the string that is printed after the exponent when using
scientific notation.
-
setPrecision(int)
- Set the precision (number of digits after the decimal point).
-
setPreExponent(String)
- Set the string that is printed before the exponent when using
scientific notation.
-
setRightPadChar(char)
- Set the char that will be used to pad on the right hand side.
-
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.
-
setRoundingMethod(int)
- Set the rounding method to be used when decreasing the number
of digits for numbers that implement the Formattable interface.
-
setShowDecimalOnInteger(boolean)
- Set whether the decimal symbol should be shown on integer valued
floating point numbers.
-
setSignOnLeft(boolean)
- Set which side the sign should appear on, true for left, false for right.
-
setUseDefaultPrecision(boolean)
- Set whether default precision should be used.
-
setWidth(int)
- Set the field width
-
showDecimalOnInteger()
- Return whether the decimal symbol will be shown on integer valued
floating point values.
-
signOnLeft()
- Return whether the sign is to appear to the left of the numeric value.
-
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.
-
useDefaultPrecision()
- Return whether default precision will be used.
NumericFormat
public NumericFormat()
- Use the default precision of 4 digits after the decimal place.
NumericFormat
public NumericFormat(int precision)
- Use the specified precision.
clone
public Object clone()
- Returns a clone of this NumericFormat object.
- Overrides:
- clone in class Object
getPrecision
public int getPrecision()
- Get the current precision setting.
setPrecision
public void setPrecision(int precision)
- Set the precision (number of digits after the decimal point).
Also sets useDefaultPrecision to false.
getWidth
public int getWidth()
- Get the current setting for width
setWidth
public void setWidth(int width)
- Set the field width
getDecimalSymbol
public String getDecimalSymbol()
- Return the string used to represent the decimal place.
setDecimalSymbol
public void setDecimalSymbol(String decimalSymbol)
- Set the string used to represent the decimal place, default is "."
setLeftPadChar
public void setLeftPadChar(char c)
- Set the char that will be used to pad on the left hand side.
The default is ' ' (space).
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).
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.
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.
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.
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.
signOnLeft
public boolean signOnLeft()
- Return whether the sign is to appear to the left of the numeric value.
setSignOnLeft
public void setSignOnLeft(boolean signOnLeft)
- Set which side the sign should appear on, true for left, false for right.
getPositiveSymbol
public String getPositiveSymbol()
- Return the string that will be used for a positive sign.
setPositiveSymbol
public void setPositiveSymbol(String positiveSymbol)
- Set the string that will be used for a positive sign.
parenthesesForNegative
public boolean parenthesesForNegative()
- Return whether parentheses will be used to denote negative numbers.
setParenthesesForNegative
public void setParenthesesForNegative(boolean parenthesesForNegative)
- Set whether or not parentheses will be used for negative numbers.
getRoundingMethod
public int getRoundingMethod()
- Return the rounding method used when reducing the number of digits
for numbers that implement the Formattable interface.
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.
getDecimalPosition
public int getDecimalPosition()
- Return the position within the field
at which the decimal symbol should occur.
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.
getPreExponent
public String getPreExponent()
- Return the string that is printed before the exponent when using
scientific notation.
setPreExponent
public void setPreExponent(String preExponent)
- Set the string that is printed before the exponent when using
scientific notation.
getPostExponent
public String getPostExponent()
- Return the string that is printed after the exponent when using
scientific notation.
setPostExponent
public void setPostExponent(String postExponent)
- Set the string that is printed after the exponent when using
scientific notation.
addLeadingZero
public boolean addLeadingZero()
- Return whether or not a leading '0' should be added to numbers
with no digits before the decimal place.
setAddLeadingZero
public void setAddLeadingZero(boolean addLeadingZero)
- Specify whether a leading '0' should be prepended to numbers
with no digits before the decimal place.
addTrailingZero
public boolean addTrailingZero()
- Return whether a trailing zero will be added to integer valued numbers.
setAddTrailingZero
public void setAddTrailingZero(boolean addTrailingZero)
- Set whether a trailing zero will be added to integer valued numbers.
showDecimalOnInteger
public boolean showDecimalOnInteger()
- Return whether the decimal symbol will be shown on integer valued
floating point values.
setShowDecimalOnInteger
public void setShowDecimalOnInteger(boolean showDecimalOnInteger)
- Set whether the decimal symbol should be shown on integer valued
floating point numbers.
useDefaultPrecision
public boolean useDefaultPrecision()
- Return whether default precision will be used.
setUseDefaultPrecision
public void setUseDefaultPrecision(boolean useDefaultPrecision)
- Set whether default precision should be used.
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.
format
public String format(Formattable form)
- Produce a nicely formatted String representation of the argument.
format
public String format(int i)
- Produce a nicely formatted String representation of the argument.
format
public String format(Integer i)
- Produce a nicely formatted String representation of the argument.
format
public String format(long l)
- Produce a nicely formatted String representation of the argument.
format
public String format(Long l)
- Produce a nicely formatted String representation of the argument.
format
public String format(float f)
- Produce a nicely formatted String representation of the argument.
format
public String format(Float f)
- Produce a nicely formatted String representation of the argument.
format
public String format(double d)
- Produce a nicely formatted String representation of the argument.
format
public String format(Double d)
- Produce a nicely formatted String representation of the argument.
format
public String format(boolean isPositive,
String leading,
String trailing)
- Output the argument value formatted as specified by self.
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