Jump to content

Rounding Numbers


xyn

Recommended Posts

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

Archived

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

×
×
  • Create New...

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.