//**************************************
// for :Insert Commas Into Whole Number
//**************************************
Enjoy!
//**************************************
// Name: Insert Commas Into Whole Number
// Description:If you have the need to insert commas into a whole number. i.e. 1222333 = 1,222,333
// By: John Lin
//
//
// Inputs:Whole numbers only. Simply pass in the whole number portion on your string.
//
// Returns:String with commas inserted for every three digits.
//
//Assumes:None
//
//Side Effects:If you pass in float, function will fail. Can be modified easily to handle floats. Simply convert the whole number with "intval()" then run function then concatenate decimal portion to result before returning.
//This code is copyrighted and has limited warranties.
//Please see http://www.Planet-Source-Code.com/xq/ASP/txtCodeId.1791/lngWId.8/qx/vb/scripts/ShowCode.htm
//for details.
//**************************************
function InsertCommas($strString) {
$strLength = strlen($strString);
$newstr = "";
if ($strLength >= 4) {
$cntCommaInsertsDiv = intval($strLength / 3);
$cntCommaInsertsMod = $strLength % 3;
//Holder for every 3 digits array
$arrayStringHolder = array();
//Grab digits in 3 count increments
for ($x=1;$x<=$cntCommaInsertsDiv;$x++) {
$intPosition = $x * 3;
$arrayStringHolder[$x] = substr($strString, -$intPosition, 3);
}
//Grab digits remaining
if ($cntCommaInsertsMod > 0) {
$arrayStringHolder[$x] = substr($strString, 0, $cntCommaInsertsMod);
}
//Reverse array
$arrayStringHolder = array_reverse($arrayStringHolder);
//Add commas
for ($x=0;$x