note 32729 added to function.round

From: Date: Thu, 05 Jun 2003 12:08:09 +0000
Subject: note 32729 added to function.round
Groups: php.notes 
Request: Send a blank email to php-notes+get-49785@lists.php.net to get a copy of this message
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; } ---- Manual Page -- http://www.php.net/manual/en/function.round.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32729 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32729&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32729&report=yes

« previous php.notes (#49785) next »