com.ibm.as400.ui.framework.java
Class PercentFormatter

java.lang.Object
  extended by com.ibm.as400.ui.framework.java.DataFormatter
      extended by 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.

Since:
v4r2m0
Version:
1.1, 05/19/99
Author:
B. Cragun
See Also:
DataBean, IllegalUserDataException

Constructor Summary
Constructor and Description
PercentFormatter()
          Constructs a PercentFormatter.
PercentFormatter(int minimumFractionDigits, int maximumFractionDigits)
          Constructs a PercentFormatter.
 
Method Summary
Modifier and Type Method and Description
 String format(double dNum)
          Formats a double value to a string containing a percentage.
 String format(long lNum)
          Formats a long value to a string containing a percentage.
 String format(Object obj)
          Formats an Object based on the min- and maxFractionDigits set for the PercentFormatter.
 int getMaximumFractionDigits()
          Gets the maximum number of digits that appear in the fraction.
 int getMinimumFractionDigits()
          Gets the minimum number of digits that appear in the fraction.
 Object parse(String source)
          Parses a string to produce an object.
 void setMaximumFractionDigits(int digits)
          Sets the maximum number of digits that appear in the fraction.
 void setMinimumFractionDigits(int digits)
          Sets the minimum number of digits that appear in the fraction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PercentFormatter

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

Since:
v4r2m0

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
Since:
v4r5m0
Method Detail

parse

public Object parse(String source)
             throws IllegalUserDataException
Parses a string to produce an object.

Overrides:
parse in class DataFormatter
Parameters:
source - the string to be parsed
Returns:
the object obtained by parsing the string
Throws:
IllegalUserDataException
Since:
v4r2m0

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
Since:
v4r5m0

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
Since:
v4r5m0

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 .

Overrides:
format in class DataFormatter
Parameters:
obj - a valid Double, Float, Integer, or Long object cast as an Object.
Returns:
formatted string
Since:
v4r5m0

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.
Since:
v4r5m0

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.
Since:
v4r5m0

getMaximumFractionDigits

public int getMaximumFractionDigits()
Gets the maximum number of digits that appear in the fraction.

Returns:
maximum number of digits in the fraction.
Since:
v4r5m0

getMinimumFractionDigits

public int getMinimumFractionDigits()
Gets the minimum number of digits that appear in the fraction.

Returns:
minimum number of digits in the fraction
Since:
v4r5m0