[LRUG] Prices and Precision

Marcus Roberts marcus at marcusr.org.uk
Sun Nov 18 04:14:45 PST 2007


On 18 Nov 2007, at 11:48, Thomas R. Koll wrote:

>
> Am 18.11.2007 um 12:32 schrieb Marcus Roberts:
>
> ...
>> What's the best way to store prices in a Ruby (Rails) app?  What's  
>> the
>> best SQL type for mySQL?
>
> either decimal or if you don't belief in 0.5p then integer is fine
> enough for you.
>

By suggesting integer, are you saying that storing the values in pence  
rather than pounds is the way to do it?

I currently use decimals on the SQL side:

  add_column :client_timesheets, :a_rate, :decimal, :precision =>  
9, :scale => 2

So I get a charge by multiplying this by the number of hours.  I then  
need to charge VAT on that, which must be rounded, which is where I  
introduce the *0.175, and where the round function starts to give  
different results.

Marcus






More information about the Chat mailing list