You are here: Re: Missing 0.0000001 - driving me crazy - help! « PHP Programming Language « IT news, forums, messages
Re: Missing 0.0000001 - driving me crazy - help!

Posted by Philip Ronan on 12/05/05 14:15

"mat" wrote:

> Thanks Philip and Ian, a real help.
>
> Working on what Philip said about Windows just rounding, I did the same
> and it works for me:
>
> round($_SESSION["c"]-$_SESSION["a"],2)
>
> Is this wrong / ill advised for any reason? Or just another way...

No, that's fine. Just bear in mind that the round() function returns a
floating point value, so you still shouldn't expect it to be exactly equal
to the rounded number.

This is a problem common to all programming languages, not just PHP. You
should never expect floating point values to be exactly equal to anything.
Code like this just won't work properly:

$x = 1/10;
if ($x == 0.1) { ... do something ...}

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/

 

Navigation:

[Reply to this 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

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