Re: Working with numbers
| From: | Jennifer | Date: | Fri, 04 May 2001 05:39:04 +0000 |
| Subject: | Re: Working with numbers | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-51369@lists.php.net to get a copy of this message | ||
Christian Reiniger wrote:
>
> On Thursday 03 May 2001 08:53, Jennifer wrote:
>
> > I have a shopping cart that allows decimal points for quantities.
> > I like it like that, but would like to remove any trailing zeros
> > and if the quantity is not a fraction I would like to remove the
> > decimal point too.
> >
> > What would be the easiest way to do this? I don't see any
> > function that would make it easy.
>
> It's so easy that you don't need a function for it :)
>
> $Qty = "12.470";
> $Qty_real = (double) $Qty;
>
> echo "$Qty - $Qty_real";
>
> In other words - convert it from a strin to a floating-point number and
> PHP will do the rest.
I've done some searching on the php site for more info about
double and float etc, but I don't really understand anything I
found. Can someone give me an explanation about the difference
between decimal, float, double?
Should I be using decimal as my column type in the MySQL database
or should I be using a different column type?
Jennifer