Reply to Re: Missing 0.0000001 - driving me crazy - help!

Your name:

Reply:


Posted by Gordon Burditt on 12/05/05 17:01

>print '$_SESSION["a"]: '.$_SESSION["a"].'<br />';
>print '$_SESSION["c"]: '.$_SESSION["c"].'<br />';
>print $_SESSION["c"]." - ".$_SESSION["a"].' =
>'.($_SESSION["c"]-$_SESSION["a"]);
>
>----------------- RETURNS -----------------------
>
>$_SESSION["allowance"]: 200
>$_SESSION["cart_value"]: 200.15
>200.15 - 200 = 0.14999999999998
>
>When I test on my windows box it is correct, but not when I test on my
>Unix server.

There is no exact representation of 0.15 in binary floating point.
I suggest not printing so many digits after the decimal point.
printf() should round it.

0.15 as double:
Before: 0.149999999999999966693309261245303787291049957275390625000000
Value: 0.149999999999999994448884876874217297881841659545898437500000
After: 0.150000000000000022204460492503130808472633361816406250000000

0.15 as float:
Before: 0.149999991059303283691406250000000000000000000000000000000000
Value: 0.150000005960464477539062500000000000000000000000000000000000
After: 0.150000020861625671386718750000000000000000000000000000000000

Gordon L. Burditt

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация