note 32708 deleted from function.sprintf by didou

From: Date: Wed, 25 Feb 2004 14:54:36 +0000
Subject: note 32708 deleted from function.sprintf by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-65733@lists.php.net to get a copy of this message
Note Submitter: kenrick@etecom.com ---- [Editor's note: Usually it will be simpler to use number_format() to generate the type of output the code below produces. The built-in function would be faster than using a regular expression.] here is a simple function to add commas to a number. function comma_format($num){ $number = sprintf("%01.2f", $num); while (preg_match("!(-?\d+)(\d\d\d)!", $number)) { $number = preg_replace("!(-?\d+)(\d\d\d)!","$1,$2", $number); } return $number; }

« previous php.notes (#65733) next »