On Thursday 28 February 2002 08:35, Cal Evans wrote:
> Hmmmmm...you may be on to something.  If you run this code you will see that
> about 30% of the time $ns1 IS actually 1. the funny thing is that if you
> remove the doubleval calls, $ns1 purports to have a value > than 1.
> 
> Interesting...
> <?PHP
> srand ((double) microtime() * 1000000);
> #### Income statement
> $ns1   = doubleval(number_format(rand(900,1200)*1000)) ;
> $cogs1 = doubleval(number_format(rand(450,600)*1000)) ;
> $gm1   = doubleval(number_format (($ns1 - $cogs1) * 1000));
> echo '1:'.$ns1."\n";
> echo '2:'.$cogs1."\n";
> echo '3:'.$gm1."\n";
> ?>
> 


It is supposed to always have a value > 1.  If it did what it was supposed 
to, it would always have a value between 900,000 and 1,200,000.  In the 
original code, it does.  What I can't figure out is why, even though there is 
a value > 1 for $ns1, about 70% of the time, it thinks that value is one for 
the calculation of $gm1.


> *
> * Cal Evans
> * Journeyman Programmer
> * Techno-Mage
> * http://www.calevans.com
> *
> 
> 
> -----Original Message-----
> From: Roy Cabaniss [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, February 28, 2002 8:17 AM
> To: [EMAIL PROTECTED]
> Subject: [PHP] arithmatic operation inconsistant
> 
> 
> 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
> Associate Professor of Business
> 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
> 
> 

-- 
Dr. Roy F. Cabaniss
Associate Professor of Business
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

Reply via email to