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 DataBeans 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

Constructor Index

 o PercentFormatter()
Constructs a PercentFormatter.
 o PercentFormatter(int, int)
Constructs a PercentFormatter.

Method Index

 o format(double)
Formats a double value to a string containing a percentage.
 o format(long)
Formats a long value to a string containing a percentage.
 o format(Object)
Formats an Object based on the min- and maxFractionDigits set for the PercentFormatter.
 o getMaximumFractionDigits()
Gets the maximum number of digits that appear in the fraction.
 o getMinimumFractionDigits()
Gets the minimum number of digits that appear in the fraction.
 o parse(String)
Parses a string to produce an object.
 o setMaximumFractionDigits(int)
Sets the maximum number of digits that appear in the fraction.
 o setMinimumFractionDigits(int)
Sets the minimum number of digits that appear in the fraction.

Constructors

 o PercentFormatter
 public PercentFormatter()
Constructs a PercentFormatter. This constructor defaults to not showing any fractional digits.

 o 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

Methods

 o 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
 o 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
 o 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
 o 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
 o 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.
 o 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.
 o getMaximumFractionDigits
 public int getMaximumFractionDigits()
Gets the maximum number of digits that appear in the fraction.

Returns:
maximum number of digits in the fraction.
 o 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