PHP/Development/sprintf
Содержание
sprintf %0.2f
<source lang="html4strict">
<? $tax = 1.06; $subtotal = 10.94; $total = $tax + $subtotal; $fmt_total = sprintf ("%0.2f", $total); echo "$fmt_total"; ?>
</source>
sprintf: Considers the string an integer and formats it as a decimal number
<source lang="html4strict">
<? $total = 110; $fmt_total = sprintf ("%d", $total); echo "$fmt_total"; ?>
</source>
sprintf: Considers the string an integer and formats it with that ASCII value
<source lang="html4strict">
<? $total = 110; $fmt_total = sprintf ("%c", $total); echo "$fmt_total"; ?>
</source>
sprintf: Regards the string an integer and formats it as a binary number
<source lang="html4strict">
<? $total = 10.94; $fmt_total = sprintf ("%b", $total); echo "$fmt_total"; ?>
</source>
Type Specifiers for printf() and sprintf()
<source lang="html4strict">
Specifier Input type Output Format b Integer Binary number C Integer Single character D Integer Signed decimal number U Integer Unsigned decimal number F Floating-point number Floating-point number O Integer Octal number S String String X Integer Hexadecimal number with lowercase letters X Integer Hexadecimal number with uppercase letters
</source>