note 103679 modified in language.types.float by danbrown

From: Date: Wed, 27 Apr 2011 22:13:23 +0000
Subject: note 103679 modified in language.types.float by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-179210@lists.php.net to get a copy of this message
I found that to compare floats correctly I had to use this, it works very good for doing price comparison, such as order validation to make sure final prices are correct before they send. This is make your statements return true are false correctly. <?php $number1=number_format($float1,2,'.',''); $number2=number_format($float2,2,'.'''); if($number1!=$number2){ echo 'do correction here!'; } ?> --was-- I found that to compare floats correctly I had to use this, it works very good for doing price comparison, such as order validation to make sure final prices are correct before they send. This is make your statements return true are false correctly. $number1=number_format($float1,2,'.',''); $number2=number_format($float2,2,'.'''); if($number1!=$number2){ echo 'do correction here!'; } http://php.net/manual/en/language.types.float.php

« previous php.notes (#179210) next »