formatting a number

A

Anonymous

Guest
Hi, heres situation

$number = 1;

:-D

now when i put
<?php echo $number = 1; ?>
it displays "1"

BUT :sad:

i need it to display as 0001. :shock:


:help: how do i sort this one?
 
You can try doing one more thing... a little advanced -- just add some logic to your script and check a number of digits if nr has:
1 digit -- add 000,
if 2 -- add 00
if 3 -- add 0

But im not sure if u will need it.
 
I just found a better way:
Code:
<?php sprintf("%03s",$value) ?>
I have no idea how that works though. Just replace $value with the number you want.
 
should have said this before i think.

It has to work for any number between 1 and 9999,

so i could get like

0001
0010
0100
1000

for 1, 10, 100 and 1000

If someone could provide a script to render this number, that would be appreciated :) i tried the format_number function and that sprintf thing and it doesnt want to know.
 
alright well this should work out...didnt test it though
Code:
<?php
$number = $anumbervalue;
$countnumber = str_len($number);
if ($countnumber == 3)
{
$number = "0".$number;
}
else if ($countnumber == 2)
{
$number = "00".$number;
}
else if ($countnumber == 1)
{
$number = "000".$number;
}
else
{
$number = $number;
}
echo $number;
?>
 
o xuse me

its suppose to be

Code:
<?php printf("%04s",$value) ?>

Sorry
Virtuoso
 
Back
Top