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

How to created mixed arguments function...

This way useful for create mixed arguments function. function foo() { $args = func_get_args(); print_r($args); }   foo(1, 1256, 6, 17); //mixed ...   -------------------Out-...

Delete or Remove all files and folders in a directory‎...

If you want to delete everything from folder (including subfolders) use this function. function removeDir( $dir ) { if ( is_dir( $dir ) ) { $objects = scandir( $dir ); foreach ( $o...

Download a file from web to local...

Use this function to download a file from web to local machine. function WgetFile( $URL, $dir ) { $nomefile = $dir . "/" . basename( $URL ); if ( copy( $URL, $nomefile ) ) { retu...

Gregorian to Persian Date Convertor...

Gregorian to Persian Date Convertor....