Jump to content

Archived

This topic is now archived and is closed to further replies.

pedrobcabral

Newbie calculation

Recommended Posts

Sorry guys but the following code:

[code]
<?php
$numero1 = "01";
$numero2 = "01";

$conta = $numero1 + $numero2;
echo $conta;
?>
[/code]

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)

Share this post


Link to post
Share on other sites
You need to format the output with printf()
[code]<?php

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

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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.