Re: What to use?
| From: | CPT John W. Holmes | Date: | Thu, 25 Sep 2003 20:51:01 +0000 |
| Subject: | Re: What to use? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-163998@lists.php.net to get a copy of this message | ||
From: "Robert Cummings" <robert@interjinn.com>
> On Thu, 2003-09-25 at 16:28, Jeff McKeon wrote:
> > Correct me if I'm wrong please, but I think number_format() has the
> > adverse effect of changing the value type from numeric to char and
> > therefore baring you from using it in mathematical equation later in the
> > script.
> >
> > Anyway that's what it seemed to do to me when I used it on results from
> > a MySQL query...
>
> That shouldn't happen. PHP is a typeless language and so type
> conversions are juggled on the fly. If you pass a numerical string to a
> mathematical operator, then the string will be converted to the
> appropriate value.
If you get a result of "1,234.56" from number_format() and try to use that
as a numerical value (i.e. it's converted to an int or float), you'll end up
with the value being 1, though. Everything after the first non-numeric
character is lost. That's what he's talking about.
---John Holmes...