Re: [PHP] =.='' what wrong ? just simple code, however error.



On Wed, Dec 31, 2008 at 11:15, LKSunny <ad@xxxxxxxx> wrote:
i need accuracy, how to ?

No you don't. Not the level of accuracy Per was mentioning. His
suggestion to round() is what you need. Just adjust the [optional]
second parameter to the number of decimal places you wish to round:

<?php
$credithold = 100;
for($i=1;$i<=1000;$i++){
$credithold -= 0.1;
echo round($credithold,1)."<br />\n";
}
?>


"Per Jessen" <per@xxxxxxxxxxxx> 撰寫於郵件新聞:gjg4fk$58p$1@xxxxxxxxxxxxxxxxxxx
LKSunny wrote:

<?
$credithold = 100;
for($i=1;$i<=1000;$i++){
$credithold -= 0.1;
echo "$credithold<br />";
}
//i don't know why, when run this code, on 91.3 after expect is 91.2,
however......91.200000000001
//who can help me ? and tell me why ?

It's a floating point rounding error. If you don't need the accuracy,
just round it to what you need.


/Per Jessen, Zurich



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





--
</Daniel P. Brown>
daniel.brown@xxxxxxxxxxxx || danbrown@xxxxxxx
http://www.parasane.net/ || http://www.pilotpig.net/
Unadvertised dedicated server deals, too low to print - email me to find out!


Relevant Pages

  • Amber might wearily fund our tone
    ... Somebody adjust once, chew occasionally, then enhance ... but the format except for the regiment. ... It will contribute round if Najem's birth isn't fantastic. ...
    (sci.crypt)
  • Re: And so the world turns
    ... adjust the timing of our activities. ... wouldn't it be great if all clocks all ... by capitalist factory owners whose organisation of the workers led to the demand for technology, rather than the other way round which is ...
    (uk.media.radio.archers)
  • Re: Book on Pre-MATH for cryptography and cryptanalysis.
    ... but don't adjust the bizarre attempts. ... maintain after Ricky achieves the dominant monolith's balcony? ... then enable round the inequality opposite the rehearsal. ...
    (sci.crypt)
  • Re: Tyre pressure
    ... round and adjust depending on tyre wear etc. ... The tyre pressure should ...
    (uk.rec.cars.maintenance)
  • Re: Onward Through The Fog!
    ... We need to adjust the ESC by hand as we only enter ... >> one score for the round. ... >When your club enters the 21st century, ...
    (rec.sport.golf)