List:General Discussion« Previous MessageNext Message »
From:Samrat Kar Date:July 19 2010 9:38am
Subject:RE: Decimal points
View as plain text  
SELECT IF((col1+col2) = FLOOR(col1+col2),FLOOR(col1+col2), col1+col2)

EXAMPLE>>>

SELECT IF((1+1.1) = FLOOR(1+1.1),FLOOR(1+1.1),1+1.1) Results 2.1

SELECT IF((1+1.0) = FLOOR(1+1.0),FLOOR(1+1.0),1+1.0) Results 2

Regards,

Samrat Kar

-----Original Message-----
From: Ashley M. Kirchner [mailto:ashley@stripped] 
Sent: Monday, July 19, 2010 2:35 PM
To: mysql@stripped
Subject: Decimal points

mysql> select 1+1.0;

+-------+

| 1+1.0 |

+-------+

|   2.0 |

+-------+

1 row in set (0.00 sec)

 

mysql> select 1+1.1;

+-------+

| 1+1.1 |

+-------+

|   2.1 |

+-------+

1 row in set (0.00 sec)

 

 

     Is there a way to tell MySql to only return '2' in the first select as
opposed to '2.0'?  The second select is correct and should remain as such.

 

     Basically I have two columns, one with an integer and another with a
decimal.  And I'm adding the two, but for those where the decimal has a .0,
I just want the result to not have the .0 and for those that do have
anything other than .0, to display it accordingly.

 

mysql> select version();

+------------+

| version()  |

+------------+

| 5.1.47-log |

+------------+


Thread
Decimal pointsAshley M. Kirchner19 Jul
  • Re: Decimal pointsMark Goodge19 Jul
    • Re: Decimal pointsChris W20 Jul
      • Re: [MySQL] Re: Decimal pointsAshley M. Kirchner20 Jul
        • RE: [MySQL] Re: Decimal pointsSteven Staples20 Jul
  • RE: Decimal pointsSamrat Kar19 Jul
Re: Decimal pointsNguyen Manh Cuong19 Jul