Currency class?

Discussion in 'Java' started by Neill, Jun 15, 2004.

  1. Neill

    Neill Guest

    I'm working on a shopping cart application and need to crunch some currency
    numbers. This has been discussed on mailing lists I monitor, and it seems
    the recommended way is to create a currency class. Any pointers, examples,
    suggestions? TIA
    --

    Neill Laney
    http://www.laneyconsulting.com
     
    Neill, Jun 15, 2004
    #1
    1. Advertising

  2. Neill

    Roedy Green Guest

    On Tue, 15 Jun 2004 22:46:08 GMT, "Neill" <>
    wrote or quoted :

    >I'm working on a shopping cart application and need to crunch some currency
    >numbers. This has been discussed on mailing lists I monitor, and it seems
    >the recommended way is to create a currency class. Any pointers, examples,
    >suggestions? TIA


    you might be interested in CurrCon that displace prices in the
    viewer's native currency.

    See http://mindprod.com/products.html#CURRCON

    see also http://mindprod.com/jgloss/currency.html

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Jun 16, 2004
    #2
    1. Advertising

  3. Neill

    Tony Morris Guest

    "Neill" <> wrote in message
    news:Q_Kzc.45399$...
    > I'm working on a shopping cart application and need to crunch some

    currency
    > numbers. This has been discussed on mailing lists I monitor, and it seems
    > the recommended way is to create a currency class. Any pointers, examples,
    > suggestions? TIA
    > --
    >


    The only problem I see with that solution is the problem itself.
    The problem with the problem is that the problem is not defined.

    More specifically, "need to crunch some currency numbers" is hardly a well
    specified requirement.
    Many people under-estimate the implied consequences when the problem
    definition is unclear (as in this case).

    --
    Tony Morris
    (BInfTech, Cert 3 I.T.)
    Software Engineer
    (2003 VTR1000F)
    Sun Certified Programmer for the Java 2 Platform (1.4)
    Sun Certified Developer for the Java 2 Platform
     
    Tony Morris, Jun 16, 2004
    #3
  4. Neill

    Neill Guest

    "Roedy Green" <> wrote in message
    news:p...
    > On Tue, 15 Jun 2004 22:46:08 GMT, "Neill" <>
    > wrote or quoted :
    >
    > >I'm working on a shopping cart application and need to crunch some

    currency
    > >numbers. This has been discussed on mailing lists I monitor, and it seems
    > >the recommended way is to create a currency class. Any pointers,

    examples,
    > >suggestions? TIA

    >
    > you might be interested in CurrCon that displace prices in the
    > viewer's native currency.
    >
    > See http://mindprod.com/products.html#CURRCON
    >
    > see also http://mindprod.com/jgloss/currency.html
    >
    > --
    > Canadian Mind Products, Roedy Green.
    > Coaching, problem solving, economical contract programming.
    > See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.


    Not interested in running an applet, no control over the user's desktop. I
    can control things server side, though.

    BTW, how can you say the applet uses the latest currency conversion rates?
    Does the applet load the rates upon each use? From where?

    Neill
     
    Neill, Jun 16, 2004
    #4
  5. Neill

    Sudsy Guest

    Neill wrote:
    <snip>
    > BTW, how can you say the applet uses the latest currency conversion rates?
    > Does the applet load the rates upon each use? From where?


    Not meaning to dissuade you, but are you truly prepared for the
    complexities you're about to face? If you're performing conversions
    then you must appreciate that the rates change daily, if not more
    frequently. What are you going to do about reporting in consistent
    form? Even more challenging is when circumstances require you to
    make a full or partial refund. How do you reconcile the fact that
    the rates were different on the day the payment was made and the
    refund or credit issued?
    These are serious issues, BTW. You end up having to store the daily
    rates in a persistent store so that you can go back to a specific
    transaction and work from there.
    Sounds trivial? Suppose you accepted a payment of CDN$500 on Jan.
    1st of this year. Suppose further that you convert to US$ and the
    rate for the date was 0.7729, yielding US$386.45. The product was
    DOA and you've just received the product back at the warehouse.
    But the conversion rate today is 0.7207. Do you use that rate? If
    so then the customer will receive CDN$536.21.
    The customer will probably be very happy. But what if the rate
    changed in the other direction? Suppose the Canadian Dollar has
    risen against the greenback and the rate today is 0.7965. Using
    the daily rate will result in a refund of CDN$485.19. The customer
    could get quite upset, rightfully claiming that they remitted the
    full CDN$500, not CDN$485.19.
    Now you can try to explain how currency conversion works until
    you're blue in the face, but you're likely to end up with some
    very unhappy customers.
    Been there, done that, didn't even get the t-shirt! :-(
     
    Sudsy, Jun 16, 2004
    #5
  6. Neill

    Liz Guest

    "Neill" <> wrote in message
    news:Q_Kzc.45399$...
    > I'm working on a shopping cart application and need to crunch some

    currency
    > numbers. This has been discussed on mailing lists I monitor, and it seems
    > the recommended way is to create a currency class. Any pointers, examples,
    > suggestions? TIA
    > --
    >
    > Neill Laney
    > http://www.laneyconsulting.com
    >


    If you don't want to go insane you will want to tap into a "web service"
    that you can "consult", perhaps using SOAP, for each transaction. The
    exchange rate changes quickly, so you will need to record the parameters
    for each transaction for further processing; you can't go back and do
    another
    lookup because the value will have changed. Maybe need to store this in a
    database.
     
    Liz, Jun 16, 2004
    #6
  7. Neill

    Roedy Green Guest

    On Tue, 15 Jun 2004 23:37:13 GMT, "Neill" <>
    wrote or quoted :

    >BTW, how can you say the applet uses the latest currency conversion rates?
    >Does the applet load the rates upon each use? From where?


    See http://mindprod.com/zips/java/currcon.html
    and
    http://mindprod.com/projects/currencyconverter.html

    for details on how it works.

    It has a serialised table of conversions packed in the jar. I update
    it once a day from a table published by the Bank of Canada.

    I originally had it hooked up to Oanda but they wanted money.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Jun 16, 2004
    #7
  8. Neill

    Roedy Green Guest

    On Tue, 15 Jun 2004 20:51:59 -0400, Sudsy <>
    wrote or quoted :

    >How do you reconcile the fact that
    >the rates were different on the day the payment was made and the
    >refund or credit issued?


    on my own site the actual payment is done in a US dollars. The
    displays are for information only.

    It does get a bit strange when you bill people in foreign countries.
    You bad better stick to mentioning the billing amount in one currency
    only, even if they pay you in other ones. Otherwise it gets very
    complicated what you mean by the outstanding balance. It differs
    depending on what currencies you use and how they have fluctuated in
    the interim.


    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Jun 16, 2004
    #8
  9. Neill

    Liz Guest

    "Roedy Green" <> wrote in message
    news:...
    > On Tue, 15 Jun 2004 20:51:59 -0400, Sudsy <>
    > wrote or quoted :
    >
    > >How do you reconcile the fact that
    > >the rates were different on the day the payment was made and the
    > >refund or credit issued?

    >
    > on my own site the actual payment is done in a US dollars. The
    > displays are for information only.


    If you have ever used a credit card in another country you would know
    that the exchange rate they use is usually the day when the transaction
    is processed. The amount is charged
    in the currency of the country where the purchase was made and converted
    to the country where the user's account is registered. I did have a
    boss once that claimed that most of his foreign transactions were
    held for a considerable time before processing to take advantage of
    the trend in changing exchange rates. Nowadays, I don't think that
    happens.

    > It does get a bit strange when you bill people in foreign countries.
    > You bad better stick to mentioning the billing amount in one currency
    > only, even if they pay you in other ones. Otherwise it gets very
    > complicated what you mean by the outstanding balance. It differs
    > depending on what currencies you use and how they have fluctuated in
    > the interim.
    >
    >
    > --
    > Canadian Mind Products, Roedy Green.
    > Coaching, problem solving, economical contract programming.
    > See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Liz, Jun 16, 2004
    #9
  10. Neill

    Sudsy Guest

    Roedy Green wrote:
    <snip>
    > It does get a bit strange when you bill people in foreign countries.
    > You bad better stick to mentioning the billing amount in one currency
    > only, even if they pay you in other ones. Otherwise it gets very
    > complicated what you mean by the outstanding balance. It differs
    > depending on what currencies you use and how they have fluctuated in
    > the interim.


    I was merely attempting to hint at the potential pitfalls. You can
    record the transaction in either the source or target currency, but
    there are always going to be ways to abuse the system.
    If you standardize on target then what happens when a country de-
    valuates its currency, for example?
    Would you agree that it can get complex?
     
    Sudsy, Jun 16, 2004
    #10
  11. Neill

    Liz Guest

    "Sudsy" <> wrote in message
    news:...
    > Roedy Green wrote:
    > <snip>
    > > It does get a bit strange when you bill people in foreign countries.
    > > You bad better stick to mentioning the billing amount in one currency
    > > only, even if they pay you in other ones. Otherwise it gets very
    > > complicated what you mean by the outstanding balance. It differs
    > > depending on what currencies you use and how they have fluctuated in
    > > the interim.

    >
    > I was merely attempting to hint at the potential pitfalls. You can
    > record the transaction in either the source or target currency, but
    > there are always going to be ways to abuse the system.
    > If you standardize on target then what happens when a country de-
    > valuates its currency, for example?
    > Would you agree that it can get complex?


    No I don't agree, the "bill" should be completely nailed down at the
    time the transaction is processed. If/when the end user decides to pay
    there may be other adjustments like penalty interest, devaluation (as
    you mention), bankrupcy and a bunch of other stuff.
    For example: if I don't pay my bill for 10 years you should not have
    to go back and change the original credit card slip.

    >
     
    Liz, Jun 16, 2004
    #11
  12. Neill

    Roedy Green Guest

    On Wed, 16 Jun 2004 04:18:54 GMT, Roedy Green
    <> wrote or quoted :

    >See http://mindprod.com/zips/java/currcon.html
    >and
    >http://mindprod.com/projects/currencyconverter.html
    >
    >for details on how it works.


    I have added some new documentation on how it works:

    see http://mindprod.com/zips/java/currcon.html#MACROS
    and
    http://mindprod.com/zips/java/currcon.html#SOURCES


    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Jun 16, 2004
    #12
  13. Neill

    Neill Guest

    "Sudsy" <> wrote in message
    news:...
    > Neill wrote:
    > <snip>
    > > BTW, how can you say the applet uses the latest currency conversion

    rates?
    > > Does the applet load the rates upon each use? From where?

    >
    > Not meaning to dissuade you, but are you truly prepared for the
    > complexities you're about to face?

    <snip>

    I'm not doing conversions, just simple math. I'm going by an article from
    JavaWorld for now,
    http://www.javaworld.com/javaworld/jw-06-2001/jw-0601-cents.html

    In the article, it states BigDecimal loses accuracy around 13 digits or
    more. Just curious what other people are using.

    http://www.strikeiron.com provides currency conversion web services if you
    need accurate rates in the future.


    --

    Neill Laney
    http://www.laneyconsulting.com
     
    Neill, Jun 16, 2004
    #13
  14. Neill

    Neill Guest

    "Liz" <> wrote in message
    news:ncNzc.40482$eu.27737@attbi_s02...
    >
    > "Neill" <> wrote in message
    > news:Q_Kzc.45399$...
    > > I'm working on a shopping cart application and need to crunch some

    > currency
    > > numbers. This has been discussed on mailing lists I monitor, and it

    seems
    > > the recommended way is to create a currency class. Any pointers,

    examples,
    > > suggestions? TIA
    > > --
    > >
    > > Neill Laney
    > > http://www.laneyconsulting.com
    > >

    >
    > If you don't want to go insane you will want to tap into a "web service"
    > that you can "consult", perhaps using SOAP, for each transaction. The
    > exchange rate changes quickly, so you will need to record the parameters
    > for each transaction for further processing; you can't go back and do
    > another
    > lookup because the value will have changed. Maybe need to store this in a
    > database.



    Thanks, in fact, http://www.strikeiron.com offers just that. I'm not doing
    conversions, just simple addition and multiplying. BigInteger is working
    fine for now, just curious about statements I've heard made about creating
    your own currency class to handle financial calculations.
     
    Neill, Jun 16, 2004
    #14
  15. Neill

    Neill Guest

    "Tony Morris" <> wrote in message
    news:cao163$ihq$...
    >
    > "Neill" <> wrote in message
    > news:Q_Kzc.45399$...
    > > I'm working on a shopping cart application and need to crunch some

    > currency
    > > numbers. This has been discussed on mailing lists I monitor, and it

    seems
    > > the recommended way is to create a currency class. Any pointers,

    examples,
    > > suggestions? TIA
    > > --
    > >

    >
    > The only problem I see with that solution is the problem itself.
    > The problem with the problem is that the problem is not defined.
    >
    > More specifically, "need to crunch some currency numbers" is hardly a well
    > specified requirement.
    > Many people under-estimate the implied consequences when the problem
    > definition is unclear (as in this case).
    >
    > --
    > Tony Morris
    > (BInfTech, Cert 3 I.T.)
    > Software Engineer
    > (2003 VTR1000F)
    > Sun Certified Programmer for the Java 2 Platform (1.4)
    > Sun Certified Developer for the Java 2 Platform
    >
    >


    Sorry bout that, it's for a shopping cart application that needs simple
    multiplication and addition. BigDecimal is working fine, just curious about
    statements I've heard from other people about creating your own class to
    handle financial calculations.

    --

    Neill Laney
    http://www.laneyconsulting.com
     
    Neill, Jun 16, 2004
    #15
  16. Neill wrote:
    > I'm not doing conversions, just simple math. I'm going by an article from
    > JavaWorld for now,
    > http://www.javaworld.com/javaworld/jw-06-2001/jw-0601-cents.html
    >
    > In the article, it states BigDecimal loses accuracy around 13 digits or
    > more.


    No, it doesn't. BigDecimal *never* "loses accuracy". What the article
    states correctly is that double has a limited precision and
    the sample code uses double as an intermediary for displaying
    values via NumberFormat. Unfortunately, while the Java API proviced
    a class that allows arbitrary-precision arithmetics, it does not
    provide a means for formatting such numbers without imposing
    limits of precision.
     
    Michael Borgwardt, Jun 16, 2004
    #16
  17. Neill

    Eric Sosman Guest

    Neill wrote:
    >
    > I'm not doing conversions, just simple math. I'm going by an article from
    > JavaWorld for now,
    > http://www.javaworld.com/javaworld/jw-06-2001/jw-0601-cents.html
    >
    > In the article, it states BigDecimal loses accuracy around 13 digits or
    > more. [...]


    You've misread the article; go back and read it again.
    (The article's caveat concerns conversion from BigDecimal
    to double, not BigDecimal per se.)

    --
     
    Eric Sosman, Jun 16, 2004
    #17
  18. Neill

    Roedy Green Guest

    On Wed, 16 Jun 2004 16:40:44 GMT, "Neill" <>
    wrote or quoted :

    >In the article, it states BigDecimal loses accuracy around 13 digits or
    >more. Just curious what other people are using.


    You are thinking of double, not BigDecimal. BigDecimal lets you fill
    ram with complete precision.

    See http://mindprod.com/jgloss/currency.html for your options.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Jun 16, 2004
    #18
  19. Neill

    Roedy Green Guest

    On Wed, 16 Jun 2004 16:48:26 GMT, "Neill" <>
    wrote or quoted :

    >Sorry bout that, it's for a shopping cart application that needs simple
    >multiplication and addition. BigDecimal is working fine, just curious about
    >statements I've heard from other people about creating your own class to
    >handle financial calculations.


    You perhaps want something that tracks how many digits past the
    decimal each currency wants and display the national budgets to the
    penny.
    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Jun 16, 2004
    #19
  20. Neill

    Liz Guest

    The department of commerce provides conversion rates
    and they use six decimal places. For example
    12/19/2003 1.188733
    for euro to usd


    "Neill" <> wrote in message
    news:gK_zc.47526$...
    >
    > "Sudsy" <> wrote in message
    > news:...
    > > Neill wrote:
    > > <snip>
    > > > BTW, how can you say the applet uses the latest currency conversion

    > rates?
    > > > Does the applet load the rates upon each use? From where?

    > >
    > > Not meaning to dissuade you, but are you truly prepared for the
    > > complexities you're about to face?

    > <snip>
    >
    > I'm not doing conversions, just simple math. I'm going by an article from
    > JavaWorld for now,
    > http://www.javaworld.com/javaworld/jw-06-2001/jw-0601-cents.html
    >
    > In the article, it states BigDecimal loses accuracy around 13 digits or
    > more. Just curious what other people are using.
    >
    > http://www.strikeiron.com provides currency conversion web services if you
    > need accurate rates in the future.
    >
    >
    > --
    >
    > Neill Laney
    > http://www.laneyconsulting.com
    >
    >
     
    Liz, Jun 16, 2004
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark

    RangeValidator with currency

    Mark, Jul 10, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    1,666
    David Waz...
    Jul 11, 2003
  2. John Rebbeck

    Currency data type

    John Rebbeck, Jul 17, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    562
    Marc Hoeppner
    Jul 17, 2003
  3. E11
    Replies:
    1
    Views:
    4,900
    Thomas Weidenfeller
    Oct 12, 2005
  4. Joydeep
    Replies:
    1
    Views:
    191
  5. Pascal Ehlert
    Replies:
    7
    Views:
    146
    Stefan Rusterholz
    Feb 10, 2008
Loading...

Share This Page