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



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, Zürich

.



Relevant Pages

  • Re: [PHP] =.= what wrong ? just simple code, however error.
    ... LKSunny wrote: ... It's a floating point rounding error. ... just round it to what you need. ... /Per Jessen, Zurich ...
    (php.general)
  • Re: Rounding error in Stdev function result.
    ... But the implementation of STDEV() could ... >the 80-bit FP registers. ... Rounding error elimiated without using 80-bit FPU ... While floating point addition and multiplication are ...
    (microsoft.public.excel.worksheet.functions)
  • Re: problem with float
    ... i found the value stored is not the exact value which i gave. ... The floating point numbers are a subset of the real numbers. ... Usually the subset is based on a binary representation and so most non ... expect that a rounding error won't be introduced during the conversion to ...
    (comp.lang.c)
  • Re: Floating point rounding error
    ... Why does floating point have a rounding error? ... flaot f = 1234.12345678F; ... It doesn't have a rounding error. ... Posted via a free Usenet account from http://www.teranews.com ...
    (comp.lang.c)
  • Re: ARGH! Access cant add up?!?
    ... > The error you're seeing is called floating point error. ... > there's some rounding error. ... Bugger. ... Andy ...
    (microsoft.public.access.forms)