By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,705 Members | 1,350 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,705 IT Pros & Developers. It's quick & easy.

Never liked printf, why is it doing this?

P: n/a
Bob
Why does this:

..........

$sum_value+=$row_array[8];
}
echo "</table>";
echo "<br>Total Value of Orders: ".printf('$%01.2f',
$sum_value)."<br>";
echo "</br>Done";

Result in this?

$20500.00
Total Value of Orders: 9

Done

I have no idea where the '9' came from and why does @sum_value print
before the string?

Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
> $sum_value+=$row_array[8];
}
echo "</table>";
echo "<br>Total Value of Orders: ".printf('$%01.2f',
$sum_value)."<br>";
You want sprintf(), not printf() above.
echo "</br>Done";

Result in this?

$20500.00
Total Value of Orders: 9


What is the return value of printf()? It's *NOT* a string. It's
the length of the string it output.

Gordon L. Burditt
Jul 17 '05 #2

P: n/a
Gordon Burditt wrote:
$sum_value+=$row_array[8];
}
echo "</table>";
echo "<br>Total Value of Orders: ".printf('$%01.2f',
$sum_value)."<br>";


You want sprintf(), not printf() above.


or structure it like this:

printf("<br>Total Value of Orders: $%01.2f<br>", $sum_value);

[snip]

--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
Jul 17 '05 #3

P: n/a
*** Chris Hope wrote/escribió (Fri, 29 Apr 2005 07:41:37 +1200):
You want sprintf(), not printf() above.


or structure it like this:

printf("<br>Total Value of Orders: $%01.2f<br>", $sum_value);


O maybe: http://www.php.net/number_format

--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.