to.etc.domui.converter
Class MoneyUtil

java.lang.Object
  extended by to.etc.domui.converter.MoneyUtil

public class MoneyUtil
extends java.lang.Object

Utility class to handle all kinds of monetary value presentation and conversion. This parses a monetary amount entered in a string in a very lax way, to allow for maximal ease of use in entering currency amounts. It obeys most of the rules for european (euro) amounts but has a few specials:

Author:
Frits Jalvingh Created on Jul 29, 2009

Constructor Summary
MoneyUtil()
           
 
Method Summary
static boolean areValuesEqual(double value1, double value2)
          This operation compares two double values for equality.
static int getMoneyScale()
          Use this method for money amount rounding purposes.
static java.math.RoundingMode getRoundingMode()
          Use this method for money amount rounding purposes.
static void main(java.lang.String[] args)
           
static java.math.BigDecimal parseEuroToBigDecimal(java.lang.String input)
          Parse into a BigDecimal, return null for empty input.
static double parseEuroToDouble(java.lang.String input)
          Deprecated. 
static java.lang.Double parseEuroToDoubleW(java.lang.String input)
          Deprecated. 
static
<T> T
parseMoney(java.lang.Class<T> valueClass, java.lang.String in)
          Parse a monetary value and return the proper value type, either Double or BigDecimal.
static java.lang.String render(java.math.BigDecimal v, boolean thousands, boolean symbol, boolean trunk)
          Convert the BigDecimal to a formatted monetary value.
static java.lang.String render(double v, boolean thousands, boolean symbol, boolean trunk)
          Deprecated. 
static java.lang.String renderAsSimpleDotted(double v)
          Deprecated. 
static java.lang.String renderFullWithSign(java.math.BigDecimal v)
          Render as a full value: [C -###,###,###.00], including currency sign, thousands separator and all, using the specified currency locale.
static java.lang.String renderFullWithSign(double v)
          Deprecated. 
static java.lang.String renderTruncatedWithSign(java.math.BigDecimal v)
          Renders as a full value [C -###,###,###.##], but removes the fraction if it is all zeroes.
static java.lang.String renderTruncatedWithSign(double v)
          Deprecated. 
static double roundValue(double value)
          Deprecated. 
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MoneyUtil

public MoneyUtil()
Method Detail

parseMoney

public static <T> T parseMoney(java.lang.Class<T> valueClass,
                               java.lang.String in)
Parse a monetary value and return the proper value type, either Double or BigDecimal. FIXME Localization failure.

Type Parameters:
T -
Parameters:
valueClass -
in -
Returns:

getMoneyScale

public static int getMoneyScale()
Use this method for money amount rounding purposes.

Returns:
Returns used maximum fraction digits value.

getRoundingMode

public static java.math.RoundingMode getRoundingMode()
Use this method for money amount rounding purposes.

Returns:
rounding mode to use for currency.

parseEuroToDouble

@Deprecated
public static double parseEuroToDouble(java.lang.String input)
Deprecated. 

Deprecated - do not use double for monetary amounts - Parse into a double; return 0.0d for empty input. FIXME Localization failure!

Parameters:
input -
Returns:

parseEuroToDoubleW

@Deprecated
public static java.lang.Double parseEuroToDoubleW(java.lang.String input)
Deprecated. 

Deprecated - do not use double for monetary amounts - Parse into a double; return null for empty input. FIXME Localization failure!

Parameters:
input -
Returns:

parseEuroToBigDecimal

public static java.math.BigDecimal parseEuroToBigDecimal(java.lang.String input)
Parse into a BigDecimal, return null for empty input.

Parameters:
input -
Returns:

renderAsSimpleDotted

@Deprecated
public static java.lang.String renderAsSimpleDotted(double v)
Deprecated. 

FIXME jal 20091221 This cannot be here- currency precision is dependent on the currency used AND the function it is used in (rounding depends on where you are rounding). Renders the value as a simple amount with the dot as a decimal point and always followed by 2 digits after the dot, rounded even (0.005 = +.01).

Parameters:
v -
Returns:

render

@Deprecated
public static java.lang.String render(double v,
                                                 boolean thousands,
                                                 boolean symbol,
                                                 boolean trunk)
Deprecated. 

Deprecated - do not use double for monetary amounts.

Parameters:
v -
thousands -
symbol -
trunk -
Returns:

render

public static java.lang.String render(java.math.BigDecimal v,
                                      boolean thousands,
                                      boolean symbol,
                                      boolean trunk)
Convert the BigDecimal to a formatted monetary value.

Parameters:
v -
thousands - Render thousand separators where needed
symbol - Render the currency sign
trunk - If the fraction is all zeroes, remove the fraction.
Returns:

renderFullWithSign

@Deprecated
public static java.lang.String renderFullWithSign(double v)
Deprecated. 

Deprecated - do not use double for monetary amounts - Render as a full value: [C -###,###,###.00], including currency sign, thousands separator and all, using the specified currency locale. It always renders the fraction. formatters suck.

Parameters:
v -
Returns:

renderFullWithSign

public static java.lang.String renderFullWithSign(java.math.BigDecimal v)
Render as a full value: [C -###,###,###.00], including currency sign, thousands separator and all, using the specified currency locale. It always renders the fraction. formatters suck.

Parameters:
v -
Returns:

renderTruncatedWithSign

@Deprecated
public static java.lang.String renderTruncatedWithSign(double v)
Deprecated. 

Deprecated - do not use double for monetary amounts - Renders as a full value [C -###,###,###.##], but removes the fraction if it is all zeroes.

Parameters:
v -
Returns:

renderTruncatedWithSign

public static java.lang.String renderTruncatedWithSign(java.math.BigDecimal v)
Renders as a full value [C -###,###,###.##], but removes the fraction if it is all zeroes.

Parameters:
v -
Returns:

main

public static void main(java.lang.String[] args)

roundValue

@Deprecated
public static double roundValue(double value)
Deprecated. 

Deprecated - do not use double for monetary amounts.

Parameters:
value -
Returns:

areValuesEqual

public static boolean areValuesEqual(double value1,
                                     double value2)
This operation compares two double values for equality. Because floating point calculations may involve rounding, calculated double values may not be accurate, so we need to compare with certain tolerance. Since we are using rounding of monetary calculations with predefined precisions, we reuse same tolerance here, so both specified double values are compared as rounded monetary values.

Parameters:
value1 -
value2 -
Returns: