Jump to content


Photo

How do I turn 000123 to 123?


  • Please log in to reply
4 replies to this topic

#1 briant

briant
  • Members
  • PipPipPip
  • Advanced Member
  • 50 posts

Posted 16 September 2006 - 02:59 PM

How can I get rid of the 0's in front of a number? Thank you

#2 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 16 September 2006 - 03:15 PM

number_format($number);
intval($number);

Pick one :)

#3 briant

briant
  • Members
  • PipPipPip
  • Advanced Member
  • 50 posts

Posted 16 September 2006 - 03:17 PM

Thank you. I just figured out another way too:
$num = $num+0;                    // so it would turn into a number

but I guess your way is more correct, thanks again.

btw, intval don't really work because for some reason:
echo intval(042);                    // 34

#4 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 16 September 2006 - 03:32 PM

<?php
$number = '000123';

echo number_format($number)."\n";
echo intval($number);
?>
outputs
123
123
for me...

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 16 September 2006 - 08:15 PM

<?php
echo intval(042);                    // 34
echo '<br>';
echo intval('042');                  // 42

?>

042 means treat as an octal number (base 8)

'042' string value equal to 42

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users