List:General Discussion« Previous MessageNext Message »
From:Nguyen Manh Cuong Date:July 19 2010 9:39am
Subject:Re: Decimal points
View as plain text  
Hi,

Let try '' to treat numeric as character
For example:
 select 1+'1.0';
 ==> 2
 select 1+'1.1';
 ==> 2.1


----- Original Message -----
From: "Mark Goodge" <mark@stripped>
To: mysql@stripped
Sent: Monday, July 19, 2010 4:31:51 PM
Subject: Re: Decimal points

On 19/07/2010 10:04, Ashley M. Kirchner wrote:
>
>       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.

Not easily, no.

>       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.

This is the sort of thing that is far better handled in the application 
layer, rather than the database layer. PHP, for example, even has a 
built-in function which will do this:

setype($value,"float");


for example:

<?
$val = "2.1";
setype($val,"float");
echo $val;
?>

=> 2.1

<?
$val = "2.0";
setype($val,"float");
echo $val;
?>

=> 2

http://www.php.net/manual/en/function.settype.php

Even if other languages don't have built-in functions to do this, it's a 
trivial piece of code to recreate it.

Mark
-- 
http://mark.goodge.co.uk

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/mysql?unsub=1


-- 
Best Regards,
Cuongmc.

-- 
Nguyen Manh Cuong
Phong Ky Thuat - Cong ty Vien Thong So - VTC
Dien thoai: 0912051542
Gmail     : philipscuong@stripped
YahooMail : philipscuong@stripped
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