Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I have question about sprintf function. 1

Status
Not open for further replies.

ryojung

Programmer
May 28, 2000
6
SV
I have question about sprintf function. such as

$mday =sprintf("%02d",$mday);

look at "d" . Sometime I see d and sometime I see "f" I want to know how difference d and f ? And expect d,f have other a,b,c,...,z ?

Thank you
 
Thank you very much.
hmm... Have web site example about sprintf ?

Thank again.
 
$var = sprintf("%s %02d, %04d", $month, $day, $year);
print "Today is $var.";

Should return "Today is August 24, 2000."

The number before the d is the minimum field width, eg. '2' would be printed ' 2' in the $day field. Since there is a 0 in front of the two, then the justification is filled with zeros, eg '2' would be printed '02'.
 
hello ryojung,
here is some tips which wil be helpful for u
the various sprintf formats are :
%c - character
%s - String
%d - Signed int in decimal notation
%u - Unsigned int in decimal notation
%o - Unsigned int in octal notation (*****it is not %zero )
%x - Unsigned int in hexadecimal notation.
%e - Floating point no in scientific notation.
%f - Floating point no, in fixed decimal notation.
%g - Floating point no in %e or %f formats
%X - Same as %x but using capital letters for hex
representation.
%p - Pointer prints the memory address of a variable in
hexadecimal
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top