note 32729 deleted from function.round by alindeman

From: Date: Thu, 05 Jun 2003 12:14:15 +0000
Subject: note 32729 deleted from function.round by alindeman
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-49788@lists.php.net to get a copy of this message
Note Submitter: matt.squirrell@hsmx.com ---- PHP does not round backwards, which creates trouble when trying to calculate currency correctly. Here is a function to convert an interger to a correctly formatted string. function money($text) { $text = round($text, 2); if (substr ($text, -3, 1) == ".") { return $text; } if (substr ($text, -2, 1) == ".") { $text = "$text"."0"; return $text; } $text = "$text".".00"; return $text; }

« previous php.notes (#49788) next »