note 31261 added to language.types.float

From: Date: Tue, 15 Apr 2003 16:27:35 +0000
Subject: note 31261 added to language.types.float
Groups: php.notes 
Request: Send a blank email to php-notes+get-46649@lists.php.net to get a copy of this message
I was programming an accounting application in MySql that required me to sum a collection of floats and ensure that they equal zero before commiting a transaction, but as seen above a sum of floats cannot always be trusted (as was my case). I kept getting a very small remainder (like 1.4512431231e-14). Since I had used number_format(num,2) to set the precision of the numbers in the database to only two (2) decimal places, when the time comes to calculate the sum I simply multiply every number by ten (10), therby eliminating and decimal places and leaving me with integers to preform my sum. This worked great. -- http://www.php.net/manual/en/language.types.float.php http://master.php.net/manage/user-notes.php?action=edit+31261 http://master.php.net/manage/user-notes.php?action=delete+31261 http://master.php.net/manage/user-notes.php?action=reject+31261

« previous php.notes (#46649) next »