Ask a Question related to PHP Development, Design and Development.
-
Michael #1
Displaying numbers with 2 digits
Hi,
I have something like :
$c=$a+$b;
echo $c,
The thing is, i want the result to be a 2 digit number (ie 05 and not 5).
How 2 ?
Thanks in advance.
Michael
Michael Guest
-
Page Numbers not all Displaying
In one particular document I am working on, I can't seem to get some of my page numbers to display. I have applied the master to those pages. Also,... -
stripping non digits
Can anyone point me to a routine to strip anything but digits and a decimal point out of a string? Thx, Ike -
Displaying numbers in forms
Is there any way to display a number in one field as simply a number and to have that same number spelled out in another linked (or something) field?... -
displaying page numbers when scrolling
When I first installed Acrobat and scrolled some document in it, moving along the scroll bar using the mouse cursor (dragging the scroll bar down, so... -
Recognizing digits
Hi, I have a field on the stage named, "typeBox", and a button named "unlock". If a user types into the field, a number which is larger than 9,... -
Kevin Thorpe #2
Re: Displaying numbers with 2 digits
Michael wrote:
$c = $a+$b;> Hi,
>
> I have something like :
> $c=$a+$b;
> echo $c,
>
> The thing is, i want the result to be a 2 digit number (ie 05 and not 5).
> How 2 ?
printf('%2u',$c);
...or..
$c = sprintf('%2u',$a+$b);
echo $c;
Kevin Thorpe Guest
-
Michael Fuhr #3
Re: Displaying numbers with 2 digits
"Michael" <michaperso@easynet.fr> writes:
See the documentation for printf() and sprintf() in the PHP manual.> I have something like :
> $c=$a+$b;
> echo $c,
>
> The thing is, i want the result to be a 2 digit number (ie 05 and not 5).
[url]http://www.php.net/manual/en/ref.strings.php[/url]
[url]http://www.php.net/manual/fr/ref.strings.php[/url]
--
Michael Fuhr
[url]http://www.fuhr.org/~mfuhr/[/url]
Michael Fuhr Guest
-
Pedro Graca #4
Re: Displaying numbers with 2 digits
Michael wrote:
+ is an arithmetic operator> Hi,
>
> I have something like :
> $c=$a+$b;
> echo $c,
>
> The thing is, i want the result to be a 2 digit number (ie 05 and not 5).
> How 2 ?
[url]http://www.php.net/manual/en/language.operators.arithmetic.php[/url]
I think you want the
.. string operator
[url]http://www.php.net/manual/en/language.operators.string.php[/url]
<?php
$as = "0";
$bs = "5";
$cs = "0";
$an = 0;
$bn = 5;
$cn = 0;
echo $as + $bs; ### 5
echo $as . $bs; ### 05
echo $bs + $cs; ### 5
echo $bs . $cs; ### 50
echo $an + $bn; ### 5
echo $an . $bn; ### 05
echo $bn + $cn; ### 5
echo $bn . $cn; ### 50
?>
Or, if I misunderstood you, use the number_format() or printf()
functions
[url]http://www.php.net/number_format[/url]
[url]http://www.php.net/printf[/url]
HTH
--
..sig
Pedro Graca Guest
-
Michael Fuhr #5
Re: Displaying numbers with 2 digits
Kevin Thorpe <kevin@pricetrak.com> writes:
Using %2u results in a leading space, not a leading zero as stated> Michael wrote:>> >
> > I have something like :
> > $c=$a+$b;
> > echo $c,
> >
> > The thing is, i want the result to be a 2 digit number (ie 05 and not 5).
> > How 2 ?
> $c = $a+$b;
> printf('%2u',$c);
>
> ..or..
>
> $c = sprintf('%2u',$a+$b);
> echo $c;
in the requirement. See the documentation for sprintf() to find
out how to get leading zeros.
--
Michael Fuhr
[url]http://www.fuhr.org/~mfuhr/[/url]
Michael Fuhr Guest
-
Michael #6
Re: Displaying numbers with 2 digits
> Using %2u results in a leading space, not a leading zero as stated in
> the requirement. See the documentation for sprintf() to find out howIt's "%02d"> to get leading zeros.
Thanx folks !
Michael Guest



Reply With Quote

