note 25376 added to function.number-format

From: Date: Fri, 20 Sep 2002 20:57:57 +0000
Subject: note 25376 added to function.number-format
Groups: php.notes 
Request: Send a blank email to php-notes+get-37072@lists.php.net to get a copy of this message
I work in a stock broker here in Brazil. My boss asked howto parse a text archive with financial values. I decide to do it in PHP, using my intranet infra-structure. Using number_format() i was unable to format "481621350" for my country currency -> "4.816.213,50", and i had to do it manually. I´ll create a class just for it If you have some problems with this function, try this simple code above: $value='481621350'; // Initial value // Temporary variables 1 $aa = substr($value,(strlen($value) - 2),2); // The '2' specify how many characters after ',' $bb = substr($value,0,(strlen($value) - 2)); if (strlen($bb) > 3) { $cc = substr($bb, 0,strlen($bb)-3); // The '3' specify 3 decimal characters $dd = substr($bb, strlen($bb)-3,3); if (strlen($cc) > 3) { $cc1 = substr($cc, 0,strlen($cc)-3); $dd1 = substr($cc, strlen($cc)-3,3); $cc = $cc1.".".$dd1; } $bb = $cc.".".$dd; } $value = $bb.",".$aa; // Returns "4.816.213,50" - only for XXX.XXX.XXX,XX mask I´ll post a class to solve it... -- http://www.php.net/manual/en/function.number-format.php http://master.php.net/manage/user-notes.php?action=edit+25376 http://master.php.net/manage/user-notes.php?action=delete+25376 http://master.php.net/manage/user-notes.php?action=reject+25376

« previous php.notes (#37072) next »