Re: Round a number
| From: | Peter Beckman | Date: | Fri, 03 Oct 2003 15:30:00 +0000 |
| Subject: | Re: Round a number | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-30824@lists.php.net to get a copy of this message | ||
On Fri, 3 Oct 2003, Shaun wrote:
> I have a query that returns a number from culculation in my table. It
> returns say 4.00, 8.75, 0.00, 12.50 etc. How can I get MySQL to return the
> number without any zeros, i.e. 4, 8.75, 0, 12.5 etc?
You can't in MySQL. At least not that I could figure out.
In PHP you could write code to do it.
$float = 4.00;
$text = (string)$float;
if (preg_match("/\d+\.0+$/", $text)) {
list($final) = (int)split("\.", $text);
} elseif {
... blah blah blah
}
code is untested, I may have written it wrong.
---------------------------------------------------------------------------
Peter Beckman Internet Guy
beckman@purplecow.com http://www.purplecow.com/
---------------------------------------------------------------------------