Re: Floating numbers truncating to two digits without rounding
| From: | Anas Mughal | Date: | Wed, 11 Jan 2006 01:40:10 +0000 |
| Subject: | Re: Floating numbers truncating to two digits without rounding | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-228445@lists.php.net to get a copy of this message | ||
Oh, yes, Gerry has provided very useful links.
You could definetly look into using something like:
printf( "%.2f", $x );
--
Anas Mughal
On 1/10/06, Gerry Danen <gdanen@gmail.com> wrote:
>
> sprintf creates a string ready for you to manipulate. So does
> number_format. Pick whatever is best for your purpose.
>
> See http://uk2.php.net/manual/en/function.sprintf.php and
> http://uk2.php.net/manual/en/function.number-format.php for
> more info.
>
> Gerry
>
>
> On 1/10/06, Mark Steudel <mark@netriver.net> wrote:
> > Can I do this all with sprintf or do I then need to convert it to a
> string
> > and chop off what I don't want?
> >
> > -----Original Message-----
> > From: Gerry Danen [mailto:gdanen@gmail.com]
> > Sent: Monday, January 09, 2006 3:35 PM
> > To: php-general@lists.php.net
> > Subject: Re: [PHP] Floating numbers truncating to two digits without
> > rounding
> >
> > Mark,
> >
> > Why not use sprintf() with an arbitrary large number of decimals and
> then
> > discard all but the 2 you want. I.e., format with 10 decimals and then
> drop
> > the last 8.
> >
> >
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Anas Mughal