comas and smurf

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

comas and smurf

Post 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.....
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Try this:
number_format()

Mac
User avatar
cheatboy00
Forum Contributor
Posts: 151
Joined: Sat Jun 29, 2002 10:36 am
Location: canada
Contact:

Post 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
Post Reply