6
$agent = sprintf("%.5s", "James Bond, 007");
8
echo("sprintf string truncate test: ");
9
if ($agent == "James") {
15
echo("sprintf padding and align test: ");
16
$test = sprintf("abc%04d %-20s%c", 20, "fisketur", 33);
17
if ($test == "abc0020 fisketur !") {
23
echo("sprintf octal and hex test: ");
24
$test = sprintf("%4o %4x %4X %0"."8x", 128, 1024, 49151, 3457925);
25
if ($test == " 200 400 BFFF 0034c385") {
31
echo("sprintf octal binary test: ");
32
$test = sprintf("%b", 3457925);
33
if ($test == "1101001100001110000101") {
39
echo("sprintf float test: ");
40
$test = sprintf("%0"."06.2f", 10000/3.0);
41
if ($test == "003333.33") {
47
echo sprintf("%.2f\n", "99.00");
48
echo sprintf("%.2f\n", 99.00);
50
echo sprintf("%e\n", 1.234E-18);
51
echo sprintf("%e\n", 1.234E+18);
52
echo sprintf("%e\n", 9843243.12);
53
echo sprintf("%e\n", -9843243.12);
57
sprintf string truncate test: passed
58
sprintf padding and align test: passed
59
sprintf octal and hex test: passed
60
sprintf octal binary test: passed
61
sprintf float test: passed