com.ftlabs.fisa.util
Class PriceFractionFormat

java.lang.Object
  extended by java.text.Format
      extended by com.ftlabs.fisa.util.PriceFractionFormat
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class PriceFractionFormat
extends java.text.Format

A class to format price values so that the fractional part is rounded to the nearest 32nds, 64ths, 128ths, 256ths, or 512ths. Example : Using PrecisionUnit._64 : 100.984 = 100-31+ = 100.984375

See Also:
Serialized Form

Nested Class Summary
static class PriceFractionFormat.PrecisionUnit
           
 
Nested classes/interfaces inherited from class java.text.Format
java.text.Format.Field
 
Constructor Summary
PriceFractionFormat()
          Create a new instance of PriceFractionFormat using PrecisionUnit._64 and "-" as the fractionDelimiter.
PriceFractionFormat(PriceFractionFormat.PrecisionUnit precisionUnit)
          Create a new instance of PriceFractionFormat using the provided PrecisionUnit, and "-" as the fractionDelimiter.
 
Method Summary
 java.lang.String format(double value)
          A specialization of format that accepts a primitive double.
 java.lang.StringBuffer format(java.lang.Object number, java.lang.StringBuffer stringBuffer, java.text.FieldPosition fieldPosition)
          Formats a number to be represented to precisionUnit values and appends the resulting text to the given string buffer.
 double parse(java.lang.String text)
          Parses a string representing a number where the fractional value is rounded to precisionUnit value.
 java.lang.Object parseObject(java.lang.String text, java.text.ParsePosition parsePosition)
          Parses a string representing a number where the fractional value is rounded to the nearest precisionUnit value.
 
Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PriceFractionFormat

public PriceFractionFormat()
Create a new instance of PriceFractionFormat using PrecisionUnit._64 and "-" as the fractionDelimiter.


PriceFractionFormat

public PriceFractionFormat(PriceFractionFormat.PrecisionUnit precisionUnit)
Create a new instance of PriceFractionFormat using the provided PrecisionUnit, and "-" as the fractionDelimiter.

Parameters:
precisionUnit - The PrecisionUnit used to determine the level of precision for this PriceFractionFormat object.
Method Detail

format

public java.lang.String format(double value)
A specialization of format that accepts a primitive double.


format

public java.lang.StringBuffer format(java.lang.Object number,
                                     java.lang.StringBuffer stringBuffer,
                                     java.text.FieldPosition fieldPosition)
Formats a number to be represented to precisionUnit values and appends the resulting text to the given string buffer. The number can be of any subclass of Number.

Specified by:
format in class java.text.Format
Parameters:
number - The number to format
stringBuffer - the StringBuffer to which the formatted text is to be appended
fieldPosition - On input: an alignment field, if desired. On output: the offsets of the alignment field.
Returns:
the value passed in as stringBuffer

parse

public double parse(java.lang.String text)
             throws java.text.ParseException
Parses a string representing a number where the fractional value is rounded to precisionUnit value.

Parameters:
text - The text to be parsed as a decimal.
Returns:
a double that contains the translated value.
Throws:
java.text.ParseException

parseObject

public java.lang.Object parseObject(java.lang.String text,
                                    java.text.ParsePosition parsePosition)
Parses a string representing a number where the fractional value is rounded to the nearest precisionUnit value.

Specified by:
parseObject in class java.text.Format
Parameters:
text - The text to be parsed as a decimal.
parsePosition - A ParsePosition object, used to determine the starting position within the text string, and to indicate the next position after parsing.
Returns:
a Double that holds the translated value.