Re: [PHP-DB] Round a number

2003-10-03 Thread Ignatius Reilly
I just realized that this does not work with integers such as 80,
so one should add a test condition:

SELECT
IF(
 ROUND( mycol ) = mycol,
 mycol,
 TRIM( TRAILING
'.'
FROM TRIM( TRAILING '0' FROM mycol )
   )
)

Ignatius
_
- Original Message -
From: "Ignatius Reilly" <[EMAIL PROTECTED]>
To: "DB list PHP" <[EMAIL PROTECTED]>; "Shaun" <[EMAIL PROTECTED]>
Sent: Friday, October 03, 2003 5:27 PM
Subject: Re: [PHP-DB] Round a number


> SELECT
> TRIM( TRAILING
>   '.'
>   FROM TRIM( TRAILING '0' FROM mycol )
>  )
>
>
> Ignatius
> _
> - Original Message -----
> From: "Shaun" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Friday, October 03, 2003 5:12 PM
> Subject: [PHP-DB] Round a number
>
>
> > Hi,
> >
> > 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?
> >
> > Thanks for your help
> >
> > --
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DB] Round a number

2003-10-03 Thread Dillon, John
This should do it:

http://www.mysql.com/doc/en/Miscellaneous_functions.html
FORMAT(X,D) 
Formats the number X to a format like '#,###,###.##', rounded to D decimals,
and returns the result as a string. If D is 0, the result will have no
decimal point or fractional part: 
mysql> SELECT FORMAT(12332.123456, 4);
-> '12,332.1235'
mysql> SELECT FORMAT(12332.1,4);
-> '12,332.1000'
mysql> SELECT FORMAT(12332.2,0);
-> '12,332'

John


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
















   http://www.cantor.com
CONFIDENTIAL: This e-mail, including its contents and attachments, if any, are 
confidential. If you are not the named recipient please notify the sender and 
immediately delete it. You may not disseminate, distribute, or forward this e-mail 
message or disclose its contents to anybody else. Copyright and any other intellectual 
property rights in its contents are the sole property of Cantor Fitzgerald.
 E-mail transmission cannot be guaranteed to be secure or error-free. The sender 
therefore does not accept liability for any errors or omissions in the contents of 
this message which arise as a result of e-mail transmission.  If verification is 
required please request a hard-copy version.
 Although we routinely screen for viruses, addressees should check this e-mail and 
any attachments for viruses. We make no representation or warranty as to the absence 
of viruses in this e-mail or any attachments. Please note that to ensure regulatory 
compliance and for the protection of our customers and business, we may monitor and 
read e-mails sent to and from our server(s). 

For further important information, please read the  Important Legal Information and 
Legal Statement at http://www.cantor.com/legal_information.html

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Round a number

2003-10-03 Thread Peter Beckman
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
[EMAIL PROTECTED] http://www.purplecow.com/
---

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Round a number

2003-10-03 Thread Ignatius Reilly
SELECT
TRIM( TRAILING
  '.'
  FROM TRIM( TRAILING '0' FROM mycol )
 )


Ignatius
_
- Original Message -
From: "Shaun" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, October 03, 2003 5:12 PM
Subject: [PHP-DB] Round a number


> Hi,
>
> 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?
>
> Thanks for your help
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DB] Round a number

2003-10-03 Thread Gary . Every
Try the rtrim function in php


Gary Every
Sr. UNIX Administrator
Ingram Entertainment
(615) 287-4876
"Pay It Forward"
mailto:[EMAIL PROTECTED]
http://accessingram.com


> -Original Message-
> From: Shaun [mailto:[EMAIL PROTECTED]
> Sent: Friday, October 03, 2003 10:12 AM
> To: [EMAIL PROTECTED]
> Subject: [PHP-DB] Round a number
> 
> 
> Hi,
> 
> 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?
> 
> Thanks for your help
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


[PHP-DB] Round a number

2003-10-03 Thread Shaun
Hi,

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?

Thanks for your help

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php