For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > November 2004 > RE: [PHP-DB] Currency and number types...









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author RE: [PHP-DB] Currency and number types...
Trevor Gryffyn

2004-11-19, 3:56 pm

You might try this:
http://us2.php.net/manual/en/function.money-format.php

Money_format()

In your database query, you can probably format the number how you want
there too... Before you even get to PHP and round()ing it inside PHP.
But do your math and using the money_format() function to display it
should work just fine I think.

-TG

> -----Original Message-----
> From: Mark Benson [mailto:markbenson@mac.com]=20
> Sent: Friday, November 19, 2004 12:36 PM
> To: php-db@lists.php.net
> Subject: [PHP-DB] Currency and number types...
>=20
>=20
> I'm trying to display data calculated by my script as a=20
> currency. The problem I have is that PHP is treating the=20
> results of the math as a 'float' number (or 'double') so I am=20
> getting results like:
>=20
> 12.0594393
>=20
> in my table. I have tried using:
>=20
> print round($foobar,2)
>=20
> but that cuts off the trailing zero on numbers that comne out=20
> as, for example '12.10' or '12.00'.
>=20
> Does anyone know a way to force PHP to print numbers to a set=20
> number of significant figures (i.e. 2) and stop the trailing=20
> zero suppression?
>=20
> --=20
> Mark Benson
>=20

http://homepage.mac.com/markbenson

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

2004-11-19, 3:56 pm

how about good old number_format()

--
Joseph Crawford Jr.
Codebowl Solutions
codebowl@gmail.com

For a GMail account
contact me OFF-LIST
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com