[PHP] Re: arithmatic operation inconsistant

```The reason that \$ns1 is getting set to 1 so many times is because you are
doing this:```
```
picking a random number between 900000 and 1200000.
using number_format to convert that number into a string such as 900,000 or 1,200,000.
Then using that *string* in a mathmatical operation.

So, for as soon as \$ns1 is greater than 1,000,000 it is *always* going to
evaluate to 1 in your third line.

At least I think so... on my machine if I do this:

\$x = number_format("1,234 + 5");

\$x gets set to "1".

Take out all but the last number_format() function and see what happens.

-philip

On Thu, 28 Feb 2002, Roy Cabaniss wrote:

> I have a very simple php page which I am creating an accounting tutorial
> from.   I am writing all of the equations on an include file and then calling
> the file at the beginning of the appropriate pages
>
> My problems lie in inconsistant arithmatic operations. For some reason the
> equation for \$gm1 does not always act as though \$ns1 has a value.  Only about
> 30% of the time does \$gm1 give the number I expect to see.  The rest of the
> time what I get is a negative (-\$cogs1 +1).   As if you had taken 1 and
> subtracted \$cogs1.  All help MUCH appreciated.
>
>
> srand ((double) microtime() * 1000000);
> #### Income statement
> \$ns1=number_format(rand(900,1200)*1000) ;
> \$cogs1=number_format(rand(450,600)*1000) ;
> \$gm1=number_format ((\$ns1 - \$cogs1) * 1000);
>
>
>
>
>
> Dr. Roy F. Cabaniss
> University of Arkansas Monticello
> http://cabanisspc.uamont.edu/~rcaban
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

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

```