Elexis API documentation
Version 2.1.6 as of December 11 2011

ch.rgw.tools
Class Money

java.lang.Object
  extended by java.lang.Number
      extended by ch.rgw.tools.Money
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<Money>

public class Money
extends java.lang.Number
implements java.lang.Comparable<Money>

A class representing Money (as you might have guessed) Simplifies and standardizes calculations with money (rounding, converting to and from strings etc.) The accepted formats of the string representation of an amount depends on the current locale by default the format of can be set to another locale if necessary (globally) The term "Amount" means here always the x.xx form of Money

Author:
gerry
See Also:
Serialized Form

Nested Class Summary
static class Money.C
           
 
Constructor Summary
Money()
          Create empty Money
Money(double amount)
          Create Money with a specified amount
Money(int cent)
          Create Money with some cents
Money(Money money)
          Double your wealth
Money(java.lang.String val)
          Create Money with a specified amount as String This might fail if the string doesn't conform to the current locale's standard currency format
 
Method Summary
 void addAmount(double amount)
          Add some money as x.xx
 void addAmount(java.lang.String amount)
          Add some money as "x.xx"
 void addCent(int cents)
          Add some cents
 void addCent(java.lang.String cents)
          Add some cents
 Money addMoney(Money money)
          Add even more (or less) Money
static java.lang.Number checkInput(java.lang.String rawValue)
          Parse an amount given as string This might fail if the string doesn't conform to the current locale's standard currency format.
 int compareTo(Money other)
           
 Money divideBy(double factor)
           
 double doubleValue()
           
 boolean equals(java.lang.Object obj)
           
 float floatValue()
           
 double getAmount()
          return the collected amount as x.xx
 java.lang.String getAmountAsString()
          return the amount as "x.xx"
 int getCents()
          Return all the cents (but keep them anyway :-)
 java.lang.String getCentsAsString()
          return the cents
 Money.C getCorrectness()
          get the class of correctness this Money might have
 double getFrac()
          Return what was over or missing after rounding
 java.lang.String getFracAsString()
           
static char getSeparator()
           
 int hashCode()
           
 int intValue()
           
 boolean isMoreThan(Money other)
           
 boolean isNegative()
          Are you in dept?
 boolean isNeglectable()
          Is it worth any effort?
 boolean isZero()
          Are you broke?
 long longValue()
           
 Money multiply(double factor)
          Multiply your wealth
 Money negate()
          Turn wealth into dept and vice versa
 Money roundTo5()
          Round the collected amount to the nearest 0.05
 void setCorrectness(Money.C correctness)
          Declare this Money ist probably not exactly what it seems to be.
static void setLocale(java.util.Locale locale)
          Set a different locale for handling Money
 Money subtractMoney(Money money)
          Reduce your wealth
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Number
byteValue, shortValue
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Money

public Money()
Create empty Money


Money

public Money(Money money)
Double your wealth


Money

public Money(int cent)
Create Money with some cents


Money

public Money(double amount)
Create Money with a specified amount


Money

public Money(java.lang.String val)
      throws java.text.ParseException
Create Money with a specified amount as String This might fail if the string doesn't conform to the current locale's standard currency format

Throws:
java.text.ParseException
Method Detail

checkInput

public static java.lang.Number checkInput(java.lang.String rawValue)
                                   throws java.text.ParseException
Parse an amount given as string This might fail if the string doesn't conform to the current locale's standard currency format. Note: In Switzerland, Separator is '.' while in Germany, Austria and Others, it is ','. So if some Computers in the network have an OS locale setting of Switzerland and others a german, amounts are entered differently. And even more: The MacOSX does not use swiss layout at all but sees always ',' as separator. So if Macintosh, Windows and Linux PC's are in he same network, we must make sure, that the decimal comma or dot is always honored correctly.

Parameters:
val - an amount
Returns:
a Number representing the mount
Throws:
java.text.ParseException

addCent

public void addCent(java.lang.String cents)
Add some cents


addCent

public void addCent(int cents)
Add some cents


addAmount

public void addAmount(double amount)
Add some money as x.xx


addAmount

public void addAmount(java.lang.String amount)
               throws java.text.ParseException
Add some money as "x.xx"

Throws:
java.text.ParseException

addMoney

public Money addMoney(Money money)
Add even more (or less) Money


subtractMoney

public Money subtractMoney(Money money)
Reduce your wealth


getCents

public int getCents()
Return all the cents (but keep them anyway :-)


getAmount

public double getAmount()
return the collected amount as x.xx


getCentsAsString

public java.lang.String getCentsAsString()
return the cents


getAmountAsString

public java.lang.String getAmountAsString()
return the amount as "x.xx"


roundTo5

public Money roundTo5()
Round the collected amount to the nearest 0.05


getFrac

public double getFrac()
Return what was over or missing after rounding


getFracAsString

public java.lang.String getFracAsString()

multiply

public Money multiply(double factor)
Multiply your wealth

Parameters:
factor -

divideBy

public Money divideBy(double factor)

negate

public Money negate()
Turn wealth into dept and vice versa

Returns:
multiply(-1.0)

isZero

public boolean isZero()
Are you broke?

Returns:
true if you are broke

isMoreThan

public boolean isMoreThan(Money other)

isNegative

public boolean isNegative()
Are you in dept?

Returns:
true if you are

isNeglectable

public boolean isNeglectable()
Is it worth any effort?

Returns:
true if not.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

setLocale

public static void setLocale(java.util.Locale locale)
Set a different locale for handling Money

Parameters:
locale -

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

compareTo

public int compareTo(Money other)
Specified by:
compareTo in interface java.lang.Comparable<Money>

doubleValue

public double doubleValue()
Specified by:
doubleValue in class java.lang.Number

floatValue

public float floatValue()
Specified by:
floatValue in class java.lang.Number

intValue

public int intValue()
Specified by:
intValue in class java.lang.Number

longValue

public long longValue()
Specified by:
longValue in class java.lang.Number

getSeparator

public static char getSeparator()

setCorrectness

public void setCorrectness(Money.C correctness)
Declare this Money ist probably not exactly what it seems to be.

Parameters:
corectness. - One of
  • ATLEAST - is probably more
  • ATMOST - is probably less
  • EXACT - is exactly what it says
  • ABOUT . is somewhere around this amount

getCorrectness

public Money.C getCorrectness()
get the class of correctness this Money might have

Returns:
the correctness classification

Elexis API documentation
Version 2.1.6 as of December 11 2011

Copyright 2005-2011 by Gerry Weirich, Elexis