SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2009
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Updating a flot is strange

    I noticed a strange problem, following is the table structure:

    currencies_id int(11) NO PRI NULL auto_increment
    title varchar(32) NO
    code char(3) NO
    symbol_left varchar(24) YES NULL
    symbol_right varchar(24) YES NULL
    decimal_point char(1) YES NULL
    thousands_point char(1) YES NULL
    decimal_places char(1) YES NULL
    value float(13,8) YES NULL
    last_updated datetime YES NULL

    using PHPMyAdmin I executed the following update statement:

    update currencies set title = 'US Dollar', code = 'USD', symbol_left = '$', symbol_right = '', decimal_point = '.', thousands_point = ',', decimal_places = '2', value = '48.3' where currencies_id = '1'

    The value filed should store 48.30 after the successful execution but I noticed it is: 48.29999924.

    For any floating value it is doing this, I tried it on my local installation as well but the same problem. Is it a MySQL Bug?

    Am I doing something stupid?

    Regards

  2. #2
    SitePoint Guru
    Join Date
    Jan 2004
    Location
    Uppsala, sverige
    Posts
    696
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Use decimal instead of float. Float is an aproximate datatype.


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
  •