Never liked printf, why is it doing this?

This is a discussion on Never liked printf, why is it doing this? within the PHP Language forums, part of the PHP Programming Forums category; Why does this: .......... $sum_value+=$row_array[8]; } echo "</table>"; echo "<br>Total Value of ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-28-2005
Bob
 
Posts: n/a
Default Never liked printf, why is it doing this?

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?

Reply With Quote
  #2 (permalink)  
Old 04-28-2005
Gordon Burditt
 
Posts: n/a
Default Re: Never liked printf, why is it doing this?

> $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
Reply With Quote
  #3 (permalink)  
Old 04-28-2005
Chris Hope
 
Posts: n/a
Default Re: Never liked printf, why is it doing this?

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
Reply With Quote
  #4 (permalink)  
Old 04-29-2005
Alvaro G Vicario
 
Posts: n/a
Default Re: Never liked printf, why is it doing this?

*** 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
--
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 11:07 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0