Re: Multiple currencies in a application

From: Alban Hertroys <alban(at)magproductions(dot)nl>
To: novnov <novnovice(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Multiple currencies in a application
Date: 2006-11-22 15:35:55
Message-ID: 45646E5B.4010900@magproductions.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

novnov wrote:
> Bumping this in hopes that someone can give me a bit of input?

Wow, nobody replied?...

> novnov wrote:
>> I'm working on an application that will eventually need to support various
>> currencies. I've never touched this area before, have dealt with dollars
>> till now. I'm not sure what the regular practices are re mulitple
>> currencies in the same application.
>>
>> The app includes calculations like price per unit, which of course
>> involves division and thus fractional monetary units. I'm more concerned
>> about that stuff than formatting/presentation.
>>
>> Users of the app will be able to identify the currency that is relevant
>> for their use, and each individual user won't be using more than one
>> currency.
>>
>> Do I handle all currency calcs in functions that adjust for currency?

A few things you'll probably want:
- Store prices in your db with their original currency
- Make sure you have up-to-date conversion rates (how up to date that
needs to be is up to you)
- Calculate actual prices on demand

We are satisfied with daily updates to our conversion rates, which we
store in a table. Conversion isn't too difficult that way.

Say you want to convert the price of a product from dollars (the
original currency) to euros, your query would look something like this:

SELECT price * target.rate / source.rate
FROM products
INNER JOIN rates source ON (products.currency = source.currency),
rates target
WHERE products.id = 1234
AND target.currency = 'euro';

I don't think you'll need any functions, unless to retrieve real-time
conversion rates somehow. Otherwise a cron job will do nicely.

--
Alban Hertroys
alban(at)magproductions(dot)nl

magproductions b.v.

T: ++31(0)534346874
F: ++31(0)534346876
M:
I: www.magproductions.nl
A: Postbus 416
7500 AK Enschede

// Integrate Your World //

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alexander Presber 2006-11-22 15:37:43 Functional Index
Previous Message Richard Broersma Jr 2006-11-22 15:17:01 Re: PGSQL Newbie