Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2002
    Location
    Montreal, Canada
    Posts
    224
    Provided Answers: 1

    Unanswered: FLOAT data type and rounding

    Anyone can explain to me how floats are rounded in MySQL. For instance, I have a table declared as such:

    create table zozo(FLOAT(12, 3) UNSIGNED); (MyISAM)

    If I do the following:

    insert into zozo(aaa) VALUES (999999997.0);
    insert into zozo(aaa) VALUES (999999999.111);

    Then:

    select * from zozo;

    I get:

    +----------------+
    | aaa |
    +----------------+
    | 1000000000.000 |
    | 1000000000.000 |
    +----------------+
    2 rows in set (0.00 sec)

    Am I missing something?

    I'm on 5.0.15-nt on Windows

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    it's not so much how FLOATs are rounded, as how they are stored

    if you want accuracy, don't use FLOAT, use DECIMAL
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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