<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ThotSpots &#187; monetary amounts</title>
	<atom:link href="http://www.thotspots.com/tag/monetary-amounts/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thotspots.com</link>
	<description>Agile Software Development</description>
	<lastBuildDate>Wed, 09 Sep 2009 18:13:09 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Monetary Amounts in Java &#8212; Feedback Wanted</title>
		<link>http://www.thotspots.com/monetary-amounts-in-java-feedback-wanted/</link>
		<comments>http://www.thotspots.com/monetary-amounts-in-java-feedback-wanted/#comments</comments>
		<pubDate>Fri, 02 Feb 2007 05:51:41 +0000</pubDate>
		<dc:creator>Craig Jones</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[monetary amounts]]></category>

		<guid isPermaLink="false">http://www.thotspots.com/?p=19</guid>
		<description><![CDATA[Last week I submitted two patches to the TimeAndMoney open source project on SourceForge (<a href="http://timeandmoney.domainlanguage.com/">timeandmoney.domainlanguage.com/</a>). One patch has to do with localization of money.  The other patch has to do with the persistence of money, via Hibernate, to/from a database (with examples for both MS SQL, and Oracle).]]></description>
			<content:encoded><![CDATA[<p>Last week I submitted two patches to the TimeAndMoney open source project on SourceForge (<a href="http://timeandmoney.domainlanguage.com/">timeandmoney.domainlanguage.com/</a>). One patch has to do with localization of money.  The other patch has to do with the persistence of money, via Hibernate, to/from a database (with examples for both MS SQL, and Oracle).<br />
<span id="more-19"></span><br />
<sttrong>Background: Our application deals with monetary amounts that have to be represented as different currencies, and do so from the perspective of different locales.  (How we format US Dollar amounts here in the States is different than how Europeans format US Dollar amounts.) These are the issues we&#8217;ve identified:<br />
</sttrong></p>
<ol>
<li>Maintaining fractions to the proper number of decimal places when doing the math.</li>
<li>Maintaining the proper association between each monetary amount and its currency, as the amount passes through the system</li>
<li>Determining what exchange rates to use when converting amounts between currencies.</li>
<li>Properly localizing a monetary amount/currency combination when converting it to a string for display purposes.</li>
<li>Properly parsing an entered string back into a monetary amount with respect to the local formatting customs.</li>
<li>Persisting the monetary amount/currency combination as a single entity/atom.</li>
</ol>
<p>There was no ready-made solution that covers all of these bases that we could find.  The java.util.Currency type can be used to represent the currency code (<a href="http://en.wikipedia.org/wiki/ISO_4217">en.wikipedia.org/wiki/ISO_4217</a>, e.g. USD, EUR), but it does not represent any actual amount, nor the exchange rates.  (One thing it does know is the number of decimal places associated with each currency.)One Money utility class we found (<a href="http://www.diasparsoftware.com/toolkit/apidocs/com/diasparsoftware/java/util/Money.html">www.diasparsoftware.com/toolkit/apidocs/com/diasparsoftware/java/util/Money.html</a>) was written by J.B.Rainsberger, the author of &#8220;JUnit Recipes&#8221; so it&#8217;s presumably quality code, but it is USD-specific.  Our research also pointed us to Martin Fowler&#8217;s &#8220;Quantity&#8221; pattern.  It combines an amount with a unit as described in his Analysis Patterns book (and online at <a href="http://www.martinfowler.com/ap2/quantity.html">www.martinfowler.com/ap2/quantity.html</a>), and the main example of how to use it is for monetary amounts.  He also has a Convertor pattern and a Money Bag pattern (book only).  We would have referenced that if we had to start completely from scratch; however, &#8230;</p>
<p>We settled on using TimeAndMoney because, at least, it has the first two points above solidly covered.  We had to add our own support for localization, though.  Also, although there was an existing side project for Hibernate support (plus one patch), it didn&#8217;t take advantage of the User Type construct in Hibernate (for Money), so we had implement that as well.  These are the patches mentioned above.  My team is anxious for feedback.</p>
<p>BTW, we haven&#8217;t tackled the exchange rate conversions yet.  I don&#8217;t ever expect to find a prepackaged solution for that, since that&#8217;s mostly a matter of subscribing to a service that provides the current rates and then just performing the arithmetic.  Of course, the application will somehow have to determine when and how to lock in the rates over time, but that&#8217;s a business rules problem, not a money representation problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thotspots.com/monetary-amounts-in-java-feedback-wanted/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
