data structure for currencies exchange

This is a discussion on data structure for currencies exchange within the C++ Programming forums, part of the General Programming Boards category; What's the best data structure for currency exchange? The exchange rate goes something like this: 1 Euro = 1.3552 First ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    108

    data structure for currencies exchange

    What's the best data structure for currency exchange?

    The exchange rate goes something like this:
    1 Euro = 1.3552

    First I was going to use double, but then I thought this class could do better:

    Code:
    class CurrencyAmount{
       public:
          // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
          long long number;
          int permillion;
          // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    };
    So I don't have to deal with floats. permillion will never exceed 1 mil in value.

    But would double be good enough for this?

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,290
    Floating point types cannot exactly represent powers of 0.1 (decimal), or several multiples thereof.

    You do the math ...... how many times will you want to multiply by a decimal fraction?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pthread question how would I init this data structure?
    By mr_coffee in forum C Programming
    Replies: 2
    Last Post: 02-23-2009, 11:42 AM
  2. Data structure implementation
    By fkheng in forum C Programming
    Replies: 3
    Last Post: 07-31-2003, 07:44 AM
  3. Help require for some data structure topics
    By jawwadalam in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 12-15-2002, 06:09 PM
  4. can't insert data into my B-Tree class structure
    By daluu in forum C++ Programming
    Replies: 0
    Last Post: 12-05-2002, 05:03 PM
  5. Dynamic Data Structure -- Which one is better?
    By Yin in forum C++ Programming
    Replies: 0
    Last Post: 04-10-2002, 11:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21