Page 1 of 1

comas and smurf

Posted: Sat May 31, 2003 10:52 pm
by cheatboy00
Well its been awhile since I was last here... I like the new look and enter page thing... I guess this goes here...

I'm trying to put comas every 3 numbers in a number... (heh can't explain things that good). Well I'm trying to do this:

123,233,444

to a number that once was this:

123233444

and I suck so it seems I can't get it working... it's probably something simple, but I haven't been working with php much, and I've lost my touch... so I need a little help... this is what I have now... which does absolutly nothing... not even 1 coma...

Code: Select all

<?php

function coma ($num) {
   $length = strlen($num);
   if ($length > 3) {
      $len = @($length / 3);
      $bye = explode (".", $len);
      $t2 = $bye[0] + 1;
      $t = 1;
      $part = array();
      while ($t != $t2) {
         $part[$t - 1] = substr($num, ($length - (3 * $t)), ($length - (3 * ($t - 1)))); 
         $t++; 
      }
      $number = substr($num, 0, ($length - (3 * ($t - 1))));
      $number += ",";
      $t--;
      while ($t != -1){
         $number += $part[$t];
         $t--;
      }
      
   }
   return $number;
}
?>
like my code? cause it looks like <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>... hope you can help.....

Posted: Sun Jun 01, 2003 3:57 am
by twigletmac
Try this:
number_format()

Mac

Posted: Tue Jun 03, 2003 11:03 am
by cheatboy00
wow.. thats great... I suck... heh.. man how do you know all this stuff... like the top 6 posters are like php gods.... thanks