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

UTF8 string length counter...

The best way to determine the character count of a UTF8 string. function strlen_utf8( $str ) { return mb_strlen( $str, 'UTF-8' ); }   //or... function strlen_utf8( $str ) { $c = 0;...

Parse a string into separate words...

Parse a string into separate words (array output). function parser($str, $char = ' ') { $str = trim($str); $str = $str . $char; $len = strlen($str); $words = array(); $w = '...

Gregorian to Persian Date Convertor...

Gregorian to Persian Date Convertor....

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...