Number Format

Format a number with grouped thousands(please visit number_format in php):

function numberformat($str, $sep=',') {
    $result = '';
    $str = $str.'';
    $c = 0;
    $num = strlen($str);
    for($i=$num-1; $i>=0; $i--) {
        if($c==3) { 
            $result = $sep.$result;
            $result = $str[$i].$result;
            $c = 0;
        } else {
            $result = $str[$i].$result;
        } 
 
        $c++;
    }
 
  return $result;
}
 
//OUT = 1,333,555
echo numberformat(1333555);

Tags

No tag here.

Recommended pages

SQL escape string function...

Escapes special characters in a string for use in an SQL statement. howewer it check get_magic_quotes_gpc function is enable or no. if true , it strips string from slashes and escaped string from spec...

Detect file extension function...

This function is used to find the file extension also you can use pathinfo() function for get information about a file path. function ext($file_name) { return substr($file_name, strrpos($fi...

Detect leap year...

Detect leap year for gregorian and shamsi date. function gLeapYear($year) { if (($year % 4 == 0) and (($year % 100 != 0) or ($year % 400 == 0))) return true; else return ...

Extract numbers from a unicode string...

Quick extract numbers from a unicode string......