I would always use an integer type for money (ie the number of pence) and never a float. The reason being that the rules for rounding monetary values do not coincide with the rules for rounding floating point numbers. The classic example is what happens when you divide £1000 by 3. You get £333.33. However if you then multiply that by 3 you get £999.99, a penny has gone missing, which is not good! The correct answer for dividing £1000 by 3 is £333.33 + £333.33 + £333.34.
<br><br>If you want more details on the best way to model money, look at Martin Fowler's analysis of the subject:<br><a href="http://martinfowler.com/ap2/quantity.html">http://martinfowler.com/ap2/quantity.html</a> (scroll down the the Money section)
<br><br><div><span class="gmail_quote">On 18/11/2007, <b class="gmail_sendername">Dan Webb</b> <<a href="mailto:dan@danwebb.net">dan@danwebb.net</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Ive been working on and off on a money plugin for Rails that's pretty<br>well developed now. It's got currency conversion, reliable maths and<br>support for active record money fields. Its not really public but if
<br>you want to have a look then:<br><br><a href="http://svn.danwebb.net/external/rails/plugins/acts_as_money/">http://svn.danwebb.net/external/rails/plugins/acts_as_money/</a><br><br>I use it in nearly all of my projects.
<br><br>On 11/18/07, Ed Davey <<a href="mailto:ed@veryreal.co.uk">ed@veryreal.co.uk</a>> wrote:<br>> ><br>> > What's the best way to store prices in a Ruby (Rails) app? What's the<br>> > best SQL type for mySQL?
<br>> ><br>><br>> I've been storing prices in pence as integers and using Brad Folkens<br>> Model Formatter:<br>><br>> <a href="http://brad.folkens.com/formatting-data-in-rails-models">http://brad.folkens.com/formatting-data-in-rails-models
</a><br>><br>> to display and enter prices in £2.99 format.<br>><br>> This is working well for me so far...<br>><br>> ED<br>><br>> _______________________________________________<br>> Chat mailing list
<br>> <a href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org</a><br>> <a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br>><br><br><br>--<br>Dan Webb
<br><a href="http://www.danwebb.net">http://www.danwebb.net</a><br><br>aim: danwrong123<br>skype: danwrong<br>_______________________________________________<br>Chat mailing list<br><a href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org
</a><br><a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br><br></blockquote></div><br>