Re: PHP3 math/date problem
| From: | (Richard Lynch) | Date: | Thu, 13 Jul 2000 01:57:14 +0000 |
| Subject: | Re: PHP3 math/date problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-6356@lists.php.net to get a copy of this message | ||
In article <3967F5E4.BDF41B99@worldnet.att.net>,
k.bogucki@worldnet.att.net (Kenneth Bogucki) wrote:
> Below is a simple timer script that simply calculates the elapsed time
> from the query of a database until the answer is obtained and
> formatted. the function utime, I found somewhere...I just added the 4th
> line of the function so that the output time is only two decimal places
> .33 instead of .337895679 etc.
>
> The problem is this-- the variables $start and $end provide correctly
> formatted numbers 9631189.34 --however, when I subtract the two
> $end-$start the answer is always in 8 or 9 dec. places (for example
> 5.05896321) instead of two....I can't figure out why, the ans should be
> two dec places, automatically...
The computer just doesn't subtract decimals the way you and I do. It
would be too slow for it to do it that way. It always introduces rounding
errors when it subtracts/adds decimal numbers.
If you're really into math, you could look up some reference books on
computer arithmetic ("floating point operations") and dig into the
details, but it's not something people want me to spew into php.general.
Not that that has always stopped me before... :-)
You're always better off to *only* round off on final output, not in between.
--
Richard Lynch | If this was worth $$$ to you, buy a CD
US Customer Support Director | from one of the artists listed here:
Zend Technologies USA | http://www.L-I-E.com/artists.htm
http://www.zend.com | (this has nothing to do with Zend,
duh!)