News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

DeveloperTutorials.com:
Floating Point Comparisons In PHP and Javascript
January 08, 2008 @ 07:57:00

On the DeveloperTutorials website, there's a new tutorial posted that warns against the perils of floating point comparisons between PHP and Javascript.

The problem is if you've done any calculations to arrive at these numbers they might actually be stored as 71.00000000001. Now if one of them is stored that way and the other isn't and you compare the two to see if they are equal you'll get a FALSE as the response, even though they should be the same. This isn't a bug, it's how floating point comparisons are designed to work.

In order to help combat this, he's provided two functions - one in PHP and one in Javascript - that compare the numbers in a more "sane" way that someone using them to store, say, currency values might want to use to compare them.

0 comments voice your opinion now!
flaoting point number compare javascript tutorial flaoting point number compare javascript tutorial


blog comments powered by Disqus

Similar Posts

Daniel Krook's Blog: Migrating PHP applications to DB2

Padraic Brady's Blog: Zend Framework Caching (Parts 1, 2 & 2b)

Jachim Coudenys: Using multiple databases in phpunit/dbunit with Composer

DevShed: Adding Validation to an Image Generator Class with PHP 5

DevShed: Completing an Extensible Website Engine with PHP 5


Community Events





Don't see your event here?
Let us know!


api voicesoftheelephpant laravel composer podcast version symfony list configure interview series introduction extension unittest release conference opinion language install community

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework