Jump to content


Photo

Newbie calculation


  • Please log in to reply
1 reply to this topic

#1 pedrobcabral

pedrobcabral
  • Members
  • PipPipPip
  • Advanced Member
  • 108 posts

Posted 27 September 2006 - 11:27 PM

Sorry guys but the following code:

<?php
$numero1 = "01";
$numero2 = "01";

$conta = $numero1 + $numero2;
echo $conta;
?>

The variable $conta outputs the number "2". How can I make it to be "02" instead of "2"?
Thank you. (I put the double quote to try to turn this a string, not a number as it is now, but I did not sucededd)


#2 Barand

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

Posted 27 September 2006 - 11:37 PM

You need to format the output with printf()
<?php

$numero1 = "01";
$numero2 = "01";

$conta = $numero1 + $numero2;
printf ('%02d', $conta);
?>

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