Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2004
    Location
    London
    Posts
    4

    Lightbulb Unanswered: Decimal number not working

    Hi fellas,

    I have a problem storing a decimal number in a MyISAM database,

    when I create a DECIMAL (10,2) field in a table I have the following issue:

    if I store the value 1.59 I can view 1.59


    if I store the value 1.50 mysql shows 1.5, what I am trying to achieve is to store 1.50

    When PHP connect to the database and display the numbers on the page the decimal position are not correct, 1.5 is not 1.50

    Any idea?

    Many many thanks for your help

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

    Re: Decimal number not working

    Originally posted by massimoMXMUS
    Hi fellas,

    I have a problem storing a decimal number in a MyISAM database,

    when I create a DECIMAL (10,2) field in a table I have the following issue:

    if I store the value 1.59 I can view 1.59


    if I store the value 1.50 mysql shows 1.5, what I am trying to achieve is to store 1.50

    When PHP connect to the database and display the numbers on the page the decimal position are not correct, 1.5 is not 1.50

    Any idea?

    Many many thanks for your help
    Well, I created a test database with 1.5, 1.50 and a few other values (DECIMAL (10, 2)) and it displays properly when queried from the MySQL client. Looks like you problem is somewhere else... Have you tried selecting those values directly from the MySQL client?

  3. #3
    Join Date
    Mar 2004
    Location
    London
    Posts
    4

    decimal (10,2)

    Hi bstjean,

    thanks for helping me,

    I use mysql front 2.5 as the client interface and when insert some data in, eg. 1.50 and I change the mouse to the next record, it updates the record and all it display is 1.5

    when I use php to retreive the data it also display 1.5 and I can't figure out why it is doin this.

    Which client do you use to connect to mysql db?

    thanks

  4. #4
    Join Date
    Sep 2002
    Location
    Montreal, Canada
    Posts
    224
    Provided Answers: 1

    Re: decimal (10,2)

    Originally posted by massimoMXMUS
    Hi bstjean,

    thanks for helping me,

    I use mysql front 2.5 as the client interface and when insert some data in, eg. 1.50 and I change the mouse to the next record, it updates the record and all it display is 1.5

    when I use php to retreive the data it also display 1.5 and I can't figure out why it is doin this.

    Which client do you use to connect to mysql db?

    thanks
    Mysql.exe on Windows (should be mysql) on Unix...

    Like:

    mysql --user=yourusername --password=yourpasssword databasename

    Then:
    Use yourdatabasename;

    Then:
    SELECT * from yourtable;

  5. #5
    Join Date
    Mar 2004
    Location
    London
    Posts
    4

    Talking It was so easy, using php

    Hi Everybody,

    I think this is a useful piece of code and all of you will need it

    My problem was this:

    After retrieving a number field from a mysql db like 1.50 or 1.60 and multipling this number * 1 the result I was getting was 1.5 or 1.6

    In fact if you also use a calculator and put 1.50 * 1 it gives you 1.5... where does the second decimal number go?

    echo "$data->price"; // 1.50
    $quantity_in_chart = 1;
    $variable = ($data->price * $quantity_in_chart); // 1.5
    $variable = sprintf("%.2f",$variable); // 1.50

    I was pulling my hair out before founding this.

    Hope this will help some other PHP/MySQL buddies

Posting Permissions

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