All Packages Class Hierarchy This Package Previous Next Index
Class com.ibm.as400.ui.framework.java.PercentFormatter
java.lang.Object
|
+----com.ibm.as400.ui.framework.java.DataFormatter
|
+----com.ibm.as400.ui.framework.java.PercentFormatter
- public class PercentFormatter
- extends DataFormatter
Formatter for exchanging percentage values between
DataBean
s and user interface components.
PercentFormatter
formats numbers and displays as percentages
according to current locale, and parses strings of percentage information into values.
If parsing is unsuccessful, an IllegalUserDataException
is thrown.
Percentage values are stored such that they are 1/100th of the percent displayed.
(e.g. 0.47 is displayed as 47%; 47% is returned as 0.47).
PercentFormatter
has a minimum and maximum number of fraction digits
used during formatting. These are optionally set in the constructor, or with the
setMinimumFractionDigits
and setMaximumFractionDigits
methods.
The default is to show no fraction digits.
- See Also:
- DataBean, IllegalUserDataException
-
PercentFormatter()
- Constructs a
PercentFormatter
.
-
PercentFormatter(int, int)
- Constructs a
PercentFormatter
.
-
format(double)
- Formats a double value to a string containing a percentage.
-
format(long)
- Formats a long value to a string containing a percentage.
-
format(Object)
- Formats an Object based on the min- and maxFractionDigits set for the PercentFormatter.
-
getMaximumFractionDigits()
- Gets the maximum number of digits that appear in the fraction.
-
getMinimumFractionDigits()
- Gets the minimum number of digits that appear in the fraction.
-
parse(String)
- Parses a string to produce an object.
-
setMaximumFractionDigits(int)
- Sets the maximum number of digits that appear in the fraction.
-
setMinimumFractionDigits(int)
- Sets the minimum number of digits that appear in the fraction.
PercentFormatter
public PercentFormatter()
- Constructs a
PercentFormatter
. This constructor defaults to not showing any fractional
digits.
PercentFormatter
public PercentFormatter(int minimumFractionDigits,
int maximumFractionDigits)
- Constructs a
PercentFormatter
. This constructor allows both minimum and maximum
fraction digits to be specified.
If minimumFractionDigits is greater than the maximumFractionDigits, the
minimumFractionDigits is used for both values.
- Parameters:
- minimumFractionDigits - the minimum number of fraction digits to appear
- maximumFractionDigits - the maximum number of fraction digits to appear
parse
public Object parse(String source) throws IllegalUserDataException
- Parses a string to produce an object.
- Parameters:
- source - the string to be parsed
- Returns:
- the object obtained by parsing the string
- Overrides:
- parse in class DataFormatter
format
public String format(double dNum)
- Formats a double value to a string containing a percentage.
- Parameters:
- dNum - the double value to format
- Returns:
- formatted string
format
public String format(long lNum)
- Formats a long value to a string containing a percentage.
- Parameters:
- lNum - the long value to format
- Returns:
- formatted string
format
public String format(Object obj)
- Formats an Object based on the min- and maxFractionDigits set for the PercentFormatter.
Throws an IllegalArgumentException if the object is not subclass of
Number
.
- Parameters:
- obj - a valid
Double
, Float
, Integer
, or Long
object cast as an Object.
- Overrides:
- format in class DataFormatter
setMinimumFractionDigits
public void setMinimumFractionDigits(int digits)
- Sets the minimum number of digits that appear in the fraction.
If the input minimum fraction digits is greater than existing maximum fraction digits,
it overrides the maximum fraction digits.
- Parameters:
- digits - the minimum number of digits in the fraction. Must be 0 or greater.
setMaximumFractionDigits
public void setMaximumFractionDigits(int digits)
- Sets the maximum number of digits that appear in the fraction.
If the input maximum fraction digits is less than existing minimum fraction digits,
it overrides the minimum fraction digits.
- Parameters:
- digits - the maximum number of digits in the fraction. Must be 0 or greater.
getMaximumFractionDigits
public int getMaximumFractionDigits()
- Gets the maximum number of digits that appear in the fraction.
- Returns:
- maximum number of digits in the fraction.
getMinimumFractionDigits
public int getMinimumFractionDigits()
- Gets the minimum number of digits that appear in the fraction.
- Returns:
- minimum number of digits in the fraction.
All Packages Class Hierarchy This Package Previous Next Index