SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: currency/Float/Double.. which is suitable for currency...

  1. #1
    SitePoint Addict
    Join Date
    Jun 2005
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    currency/Float/Double.. which is suitable for currency...

    currency/Float/Double..

    I want to store amounts of purchasing, which data type should I use in Database to store these amounts...

    And what is the difference in between them...
    [COLOR=SlateGray]
    Web Developer @ VeriQual

  2. #2
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    heaven
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The mysql documentation suggests using DECIMAL. http://dev.mysql.com/doc/refman/5.0/...ric-types.html

  3. #3
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,004
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, it should look like this in case of MySQL
    Code sql:
    CREATE TABLE tablename (
                  price DOUBLE(10,2) NOT NULL
                );

  4. #4
    SQL Consultant silver trophybronze trophy
    SitePoint Award Recipient r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    38,456
    Mentioned
    34 Post(s)
    Tagged
    1 Thread(s)
    do not use DOUBLE for money -- DOUBLE is the same as FLOAT and it is imprecise

    see Problems with Floating-Point Comparisons
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, whatever you do, you do NOT want to use floats. Use an integer inside PHP, and in the database, use either DECIMAL or INTEGER. To use an integer, you need to make the smallest unit primary. Eg. instead of 1 dollar and 50 cents, you count 150 cents.
    Last edited by kyberfabrikken; Jan 10, 2008 at 08:56. Reason: confusing typo there ..

  6. #6
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,004
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    do not use DOUBLE for money -- DOUBLE is the same as FLOAT and it is imprecise

    see Problems with Floating-Point Comparisons
    Umm sorry it was my TYPO if it can be believable because I never used DOUBLE yet in my applications.

    Code sql:
    CREATE TABLE tablename (
                  price DECIMAL(10,2) NOT NULL
                );

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •