note 45264 added to function.floor

From: Date: Tue, 31 Aug 2004 15:59:55 +0000
Subject: note 45264 added to function.floor
Groups: php.notes 
Request: Send a blank email to php-notes+get-75752@lists.php.net to get a copy of this message
Here's a way to get around jolyon's 79.99 problem (below). If you want to take a float value representing a price and drop off any fractions of a cent, use this: <?php function round_to_penny($amount){ $string = (string)($amount * 100); $string_array = split("\.", $string); $int = (int)$string_array[0]; $return = $int / 100; return $return; } print( round_to_penny(79.99999) ); //result: 79.99 ?> Probably not super efficient, but get's the job done if you've already invested in using float values. Cheers, Sam ---- Manual Page -- http://www.php.net/manual/en/function.floor.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+45264 Delete -- http://master.php.net/manage/user-notes.php?action=delete+45264&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+45264&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#75752) next »