xyn Posted March 31, 2007 Share Posted March 31, 2007 Hey guys, Basically i've got a dob feature, which is done when the user puts their dob it implodes it in this format DD/MM/YYYY. Well when i allow them to update their dob. I run a while, which displays days/months/years before their current. then selects their current then it will display the dates after their date until the limit. days = 31, months=12 years=current(2007) Basically the problem is when it displays them, it shows up as. 01 2 3 4 5 etc. I was wondering can this be rounded by 1 decimal place to show a 0 before those digits. but then make 10 as 10 not 010. my code.. <? $sqlGetDob = mysql_query("SELECT `dob` FROM `clients` WHERE `mail`='".Secure($_SESSION['username'])."'"); while($dobData = mysql_fetch_array($sqlGetDob)) { $dob_d = "01"; $dob_m = "01"; $dob_y = "1940"; $yrnow = date("Y"); $tmp = explode("/", $dobData[0]); echo("<select size=\"1\" name=\"dob_d\">"); while($dob_d < $tmp[0]) { echo("<option>$dob_d</option>"); $dob_d++; } echo("<option selected>$dob_d</option>"); while($dob_d <= "31") { echo("<option>$dob_d</option>"); $dob_d++; } echo("</select>"); ?> / <? echo("<select size=\"1\" name=\"dob_m\">"); while($dob_m < $tmp[1]) { echo("<option>$dob_m</option>"); $dob_m++; } echo("<option selected>$dob_m</option>"); while($dob_m <= "12") { echo("<option>$dob_m</option>"); $dob_m++; } echo("</select>"); ?> / <? echo("<select size=\"1\" name=\"dob_y\">"); while($dob_y < $tmp[2]) { echo("<option>$dob_y</option>"); $dob_y++; } echo("<option selected>$dob_y</option>"); while($dob_y < $yrnow) { echo("<option>$dob_y</option>"); $dob_y++; } echo("</select>"); } ?> Link to comment https://forums.phpfreaks.com/topic/45058-rounding-numbers/ Share on other sites More sharing options...
Trium918 Posted March 31, 2007 Share Posted March 31, 2007 Where do them squares come from? Link to comment https://forums.phpfreaks.com/topic/45058-rounding-numbers/#findComment-218744 Share on other sites More sharing options...
shocker-z Posted March 31, 2007 Share Posted March 31, 2007 i never found a way (talking a few years back) except to use a if statement if ($i < 10) { echo '0'.$i; } Regards Liam Link to comment https://forums.phpfreaks.com/topic/45058-rounding-numbers/#findComment-218750 Share on other sites More sharing options...
xyn Posted March 31, 2007 Author Share Posted March 31, 2007 Ahh i never thought of that method heh. but thats just as useful. thanks Link to comment https://forums.phpfreaks.com/topic/45058-rounding-numbers/#findComment-218753 Share on other sites More sharing options...
kenrbnsn Posted March 31, 2007 Share Posted March 31, 2007 The easiest way to do this is with printf() or sprintf(): <?php for ($i=1;$i<11;$i++) echo sprintf("%02d",$i).'<br>'; ?> Ken Link to comment https://forums.phpfreaks.com/topic/45058-rounding-numbers/#findComment-218803 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.