<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: 7 Top Tips for Coding With Currency</title>
	<atom:link href="http://www.setfiremedia.com/blog/7-top-tips-for-coding-with-currency/feed" rel="self" type="application/rss+xml" />
	<link>http://www.setfiremedia.com/blog/7-top-tips-for-coding-with-currency</link>
	<description>Hot ideas for the web.</description>
	<lastBuildDate>Thu, 11 Mar 2010 16:17:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Gawin</title>
		<link>http://www.setfiremedia.com/blog/7-top-tips-for-coding-with-currency/comment-page-1#comment-1250</link>
		<dc:creator>Gawin</dc:creator>
		<pubDate>Sat, 07 Nov 2009 12:39:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.setfiremedia.com/blog/?p=101#comment-1250</guid>
		<description>The Money gem now lives at:
http://money.rubyforge.org/

Code on github:
http://github.com/FooBarWidget/money/

gem install money</description>
		<content:encoded><![CDATA[<p>The Money gem now lives at:<br />
<a href="http://money.rubyforge.org/" rel="nofollow">http://money.rubyforge.org/</a></p>
<p>Code on github:<br />
<a href="http://github.com/FooBarWidget/money/" rel="nofollow">http://github.com/FooBarWidget/money/</a></p>
<p>gem install money</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Mckay</title>
		<link>http://www.setfiremedia.com/blog/7-top-tips-for-coding-with-currency/comment-page-1#comment-1248</link>
		<dc:creator>Paul Mckay</dc:creator>
		<pubDate>Fri, 06 Nov 2009 12:10:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.setfiremedia.com/blog/?p=101#comment-1248</guid>
		<description>Hey John, 

Remembered seeing this article a while back and had some recent experience with dealing with currency.

Just a quick tip for everyone, I agree totally that using floats is terrible for currency, and working with minor units as John suggest is a much better way.

Lest this bites anyone in the ass part way through a design, for e-commerce projects, don&#039;t use cents/pennies as your minor unit. The problem with that is VAT/tax calculations.  You often want to store the price ex vat against a product and then calculate the VAT afterwards.  The problem with storing your ex vat price in cents/pennies is that it&#039;s impossible (due to rounding) to get certain inc vat prices.

For this reason (according to our accountant) accounting packages store prices ex vat to 100ths of a cent/penny.  So you are much better off making that your minor unit.

(Bear in mind, companies that sell a lot internationally will charge a different VAT/tax rate according to the country they are shipping to, in these situations storing price inc vat doesn&#039;t work out).</description>
		<content:encoded><![CDATA[<p>Hey John, </p>
<p>Remembered seeing this article a while back and had some recent experience with dealing with currency.</p>
<p>Just a quick tip for everyone, I agree totally that using floats is terrible for currency, and working with minor units as John suggest is a much better way.</p>
<p>Lest this bites anyone in the ass part way through a design, for e-commerce projects, don&#8217;t use cents/pennies as your minor unit. The problem with that is VAT/tax calculations.  You often want to store the price ex vat against a product and then calculate the VAT afterwards.  The problem with storing your ex vat price in cents/pennies is that it&#8217;s impossible (due to rounding) to get certain inc vat prices.</p>
<p>For this reason (according to our accountant) accounting packages store prices ex vat to 100ths of a cent/penny.  So you are much better off making that your minor unit.</p>
<p>(Bear in mind, companies that sell a lot internationally will charge a different VAT/tax rate according to the country they are shipping to, in these situations storing price inc vat doesn&#8217;t work out).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gauda.de &#187; Blog Archive &#187; Use to_money to convert a string to an integer</title>
		<link>http://www.setfiremedia.com/blog/7-top-tips-for-coding-with-currency/comment-page-1#comment-916</link>
		<dc:creator>gauda.de &#187; Blog Archive &#187; Use to_money to convert a string to an integer</dc:creator>
		<pubDate>Mon, 03 Nov 2008 00:21:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.setfiremedia.com/blog/?p=101#comment-916</guid>
		<description>[...] You can read about the motivation why to use integer in flavor of decimals in the database here: 7 Top Tips for Coding With Currency. [...]</description>
		<content:encoded><![CDATA[<p>[...] You can read about the motivation why to use integer in flavor of decimals in the database here: 7 Top Tips for Coding With Currency. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sambeau</title>
		<link>http://www.setfiremedia.com/blog/7-top-tips-for-coding-with-currency/comment-page-1#comment-681</link>
		<dc:creator>sambeau</dc:creator>
		<pubDate>Mon, 13 Oct 2008 20:54:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.setfiremedia.com/blog/?p=101#comment-681</guid>
		<description>Just one comment: Floats are not slower than integers any more.</description>
		<content:encoded><![CDATA[<p>Just one comment: Floats are not slower than integers any more.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dev Blog AF83 &#187; Blog Archive &#187; Veille technologique : Merb, Vim, geode, iPhone, etc.</title>
		<link>http://www.setfiremedia.com/blog/7-top-tips-for-coding-with-currency/comment-page-1#comment-678</link>
		<dc:creator>Dev Blog AF83 &#187; Blog Archive &#187; Veille technologique : Merb, Vim, geode, iPhone, etc.</dc:creator>
		<pubDate>Mon, 13 Oct 2008 17:41:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.setfiremedia.com/blog/?p=101#comment-678</guid>
		<description>[...] : un plugin jQuery pour choisir l&#8217;heure en 3 clicks. * http://www.setfiremedia.com/blog/7-top-tips-for-coding-with-currency : 7 astuces pour développeurs confrontés à différentes monnaies. * [...]</description>
		<content:encoded><![CDATA[<p>[...] : un plugin jQuery pour choisir l&#8217;heure en 3 clicks. * <a href="http://www.setfiremedia.com/blog/7-top-tips-for-coding-with-currency" rel="nofollow">http://www.setfiremedia.com/blog/7-top-tips-for-coding-with-currency</a> : 7 astuces pour développeurs confrontés à différentes monnaies. * [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: links for 2008-10-08 &#124; Libin Pan</title>
		<link>http://www.setfiremedia.com/blog/7-top-tips-for-coding-with-currency/comment-page-1#comment-545</link>
		<dc:creator>links for 2008-10-08 &#124; Libin Pan</dc:creator>
		<pubDate>Thu, 09 Oct 2008 05:49:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.setfiremedia.com/blog/?p=101#comment-545</guid>
		<description>[...] 7 Top Tips for Coding With Currency &#124; The Matchbox (tags: rubyonrails ruby rails validation money) [...]</description>
		<content:encoded><![CDATA[<p>[...] 7 Top Tips for Coding With Currency | The Matchbox (tags: rubyonrails ruby rails validation money) [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: links for 2008-10-08 &#171; Donghai Ma</title>
		<link>http://www.setfiremedia.com/blog/7-top-tips-for-coding-with-currency/comment-page-1#comment-542</link>
		<dc:creator>links for 2008-10-08 &#171; Donghai Ma</dc:creator>
		<pubDate>Thu, 09 Oct 2008 03:51:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.setfiremedia.com/blog/?p=101#comment-542</guid>
		<description>[...] 7 Top Tips for Coding With Currency &#124; The Matchbox (tags: tips programming business money ecommerce) [...]</description>
		<content:encoded><![CDATA[<p>[...] 7 Top Tips for Coding With Currency | The Matchbox (tags: tips programming business money ecommerce) [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://www.setfiremedia.com/blog/7-top-tips-for-coding-with-currency/comment-page-1#comment-538</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Thu, 09 Oct 2008 00:52:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.setfiremedia.com/blog/?p=101#comment-538</guid>
		<description>Use a decimal and be done with it.</description>
		<content:encoded><![CDATA[<p>Use a decimal and be done with it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Currency</title>
		<link>http://www.setfiremedia.com/blog/7-top-tips-for-coding-with-currency/comment-page-1#comment-526</link>
		<dc:creator>Currency</dc:creator>
		<pubDate>Wed, 08 Oct 2008 18:27:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.setfiremedia.com/blog/?p=101#comment-526</guid>
		<description>[...] Main has 7 top tips for coding with currency - with Rails specifically in [...]</description>
		<content:encoded><![CDATA[<p>[...] Main has 7 top tips for coding with currency &#8211; with Rails specifically in [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Main</title>
		<link>http://www.setfiremedia.com/blog/7-top-tips-for-coding-with-currency/comment-page-1#comment-514</link>
		<dc:creator>John Main</dc:creator>
		<pubDate>Wed, 08 Oct 2008 08:22:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.setfiremedia.com/blog/?p=101#comment-514</guid>
		<description>Thanks for commenting guys

@anon - As I&#039;ve said I think the only way to go is integer arithmetic and I do think that if you work in thousandths or ten-thousandths of a penny/cent/whatever then that&#039;s the base unit you should use. As ruertar says, with 64bit ints that still allows you to represent pentillions of your major unit.
And I also agree with Pavel - that&#039;s rather worrying...

@Raoul - If you find one that always gets its sums right and doesn&#039;t clog the CPU with excessive floating point arithmetic and/or casting to and from strings then please send me a link :)

@Me - Of course you have to follow your spec and not make any arbitrary decisions about rounding. I work a lot with percentage discounts, markup etc and believe me, always rounding in one direction makes my life so much easier!

@Steve - To me that is treating the symptoms rather than the disease. If the rest of the system works perfectly well in minor units then increasing your accuracy to handle a single bug is unnecessary complication, especially when there are easier ways round it.
In this example we would be increasing the accuracy but then always wanting the additional least significant digits to be zero as any other value would represent the floating point error.

@David - I work a lot with percentage discounts and, being the nice guys we are, we round them up to the nearest penny. Hence the &#039;ceil&#039;.

@Jeremy - Nice one, I&#039;m off to check out that money class right now</description>
		<content:encoded><![CDATA[<p>Thanks for commenting guys</p>
<p>@anon &#8211; As I&#8217;ve said I think the only way to go is integer arithmetic and I do think that if you work in thousandths or ten-thousandths of a penny/cent/whatever then that&#8217;s the base unit you should use. As ruertar says, with 64bit ints that still allows you to represent pentillions of your major unit.<br />
And I also agree with Pavel &#8211; that&#8217;s rather worrying&#8230;</p>
<p>@Raoul &#8211; If you find one that always gets its sums right and doesn&#8217;t clog the CPU with excessive floating point arithmetic and/or casting to and from strings then please send me a link :)</p>
<p>@Me &#8211; Of course you have to follow your spec and not make any arbitrary decisions about rounding. I work a lot with percentage discounts, markup etc and believe me, always rounding in one direction makes my life so much easier!</p>
<p>@Steve &#8211; To me that is treating the symptoms rather than the disease. If the rest of the system works perfectly well in minor units then increasing your accuracy to handle a single bug is unnecessary complication, especially when there are easier ways round it.<br />
In this example we would be increasing the accuracy but then always wanting the additional least significant digits to be zero as any other value would represent the floating point error.</p>
<p>@David &#8211; I work a lot with percentage discounts and, being the nice guys we are, we round them up to the nearest penny. Hence the &#8216;ceil&#8217;.</p>
<p>@Jeremy &#8211; Nice one, I&#8217;m off to check out that money class right now</p>
]]></content:encoded>
	</item>
</channel>
</rss>
