how to echo a double type in php

Discussion in 'PHP' started by xbat, Oct 20, 2014.

  1. #1
    I have a mysql column that is a double.

    How would I echo it in php?

    Alll my other rows work example $row['something'];

    What I have tried with the double

    print getype($row['test']);
    echo getype($row['test']);
    PHP:
    Any suggestions I would greatly appreciate.
     
    Solved! View solution.
    Last edited by a moderator: Oct 20, 2014
    xbat, Oct 20, 2014 IP
  2. #2
    May I ask why you're using DOUBLE? What does it contain?
    Apart from that you can use PHPs number_format() or just query it directly from mysql via SELECT FORMAT(1.2345,2);
     
    PoPSiCLe, Oct 20, 2014 IP
  3. sarahk

    sarahk iTamer Staff

    Messages:
    28,895
    Likes Received:
    4,553
    Best Answers:
    123
    Trophy Points:
    665
    #3
    PHP is pretty user friendly. You should just be able to echo it out. What does it do that you don't like?
     
    sarahk, Oct 20, 2014 IP
  4. Anveto

    Anveto Well-Known Member

    Messages:
    697
    Likes Received:
    40
    Best Answers:
    19
    Trophy Points:
    195
    #4
    Just do

    
    echo $row['test'];
    
    PHP:
    php pretty much treats everything like a string.
     
    Anveto, Oct 20, 2014 IP
  5. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #5
    That is very true - I'm guessing he has values with multiple 0's and that they don't show up correctly. Hence why I asked about what was stored in the DOUBLE column. My theory is he's using DOUBLE for something he doesn't need DOUBLE for.
     
    PoPSiCLe, Oct 21, 2014 IP
  6. xbat

    xbat Well-Known Member

    Messages:
    326
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    105
    #6
    Actually I just forgot to select it :( any ways its all figured out.
     
    xbat, Oct 21, 2014 IP
  7. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #7
    Again, I'd check to see if you really want DOUBLE. If this is for saving currency information (price, for instance), DOUBLE is NOT RECOMMENDED.
     
    PoPSiCLe, Oct 22, 2014 IP
  8. xbat

    xbat Well-Known Member

    Messages:
    326
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    105
    #8

    Actually the setup is from someone else's project that is really old. I have never used it, nor did I ever really notice it was around. I am wondering why do you say that about double? Whats the down side? Currently for alot of my other projects I use decimal 14,2

    Thank you
     
    xbat, Oct 22, 2014 IP
  9. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #9
    Yeah. Decimal would be a better choice. DOUBLE is bad for currency/monetary values since it doesn't round correctly. Not necessarily a big problem, but it can quickly add up to be quite a problem after a while.
     
    PoPSiCLe, Oct 22, 2014 IP