Re: What am I doing wrong?
| From: | David T-G | Date: | Thu, 17 Apr 2003 11:59:23 +0000 |
| Subject: | Re: What am I doing wrong? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-144271@lists.php.net to get a copy of this message | ||
Warren --
..and then Warren Vail said...
%
% Does anyone see what I am doing wrong here?
Well, first off you're posting a completely unrelated question in an
existing thread. This has nothing to do with the user or group under
which the web server is running.
When you wish to start a fresh topic, don't just reply to an existing
message but instead start a fresh message. Just changing the Subject:
header (when one even remembers to do so) isn't sufficient; smart mail
programs build threads based on the Message-ID: and References: headers
and your new message appears right under the message to which you replied
(which can even mean it won't be seen if that thread has been finished
and nobody is looking back at it).
%
% <?php
%
% $monthly = 14.95;
% $qtrly = 44.85;
%
% if($qtrly != 0 && $qtrly != ($monthly * 3))
The manual explains the problems of floating point precision and equality
comparisons, particularly with multiplication involved.
From php_manual_en.html#language.types.float :
PHP Manual (p101 of 2132)
Floating point numbers
...
Floating point precision
It is quite usual that simple decimal fractions like 0.1 or 0.7 cannot
be converted into their internal binary counterparts without a little
loss of precision. This can lead to confusing results: for example,
floor((0.1+0.7)*10) will usually return 7 instead of the expected 8 as
the result of the internal representation really being something like
7.9999999999....
This is related to the fact that it is impossible to exactly express
some fractions in decimal notation with a finite number of digits. For
instance, 1/3 in decimal form becomes 0.3333333. . ..
So never trust floating number results to the last digit and never
compare floating point numbers for equality. If you really need higher
precision, you should use the arbitrary precision math functions or
gmp functions instead.
HTH & HAND
:-D
--
David T-G * There is too much animal courage in
(play) davidtg@justpickone.org * society and not sufficient moral courage.
(work) davidtgwork@justpickone.org -- Mary Baker Eddy, "Science and Health"
http://justpickone.org/davidtg/ Shpx gur
Pbzzhavpngvbaf Qrprapl Npg!