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

Change timestamp to custom format...

Use this function for change timestamp to custom format......

Gregorian to Persian Date Convertor...

Gregorian to Persian Date Convertor....

Human readable file size...

This function return formatting of file sizes in a human readable format. function formatFileSize( $size ) { $file_size = $size; $i = 0;   $name = array( 'byte', 'kB', 'MB', '...

Validate phone number...

Chek if a phone numbers is valid, according to its syntax (should be: "+390523599314"). True if it's valid, False otherwise function is_valid_phone( $phone ) { if ( $phone[0] != "+" ) { ...