Connecting Tech Pros Worldwide Help | Site Map

Never liked printf, why is it doing this?

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 12:54 PM
Bob
Guest
 
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?


  #2  
Old July 17th, 2005, 12:54 PM
Gordon Burditt
Guest
 
Posts: n/a
Default Re: Never liked printf, why is it doing this?

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

You want sprintf(), not printf() above.
[color=blue]
> echo "</br>Done";
>
>Result in this?
>
>$20500.00
>Total Value of Orders: 9[/color]

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

Gordon L. Burditt
  #3  
Old July 17th, 2005, 12:54 PM
Chris Hope
Guest
 
Posts: n/a
Default Re: Never liked printf, why is it doing this?

Gordon Burditt wrote:
[color=blue][color=green]
>>$sum_value+=$row_array[8];
>>}
>>echo "</table>";
>>echo "<br>Total Value of Orders: ".printf('$%01.2f',
>>$sum_value)."<br>";[/color]
>
> You want sprintf(), not printf() above.[/color]

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
  #4  
Old July 17th, 2005, 12:54 PM
Alvaro G Vicario
Guest
 
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):[color=blue][color=green]
>> You want sprintf(), not printf() above.[/color]
>
> or structure it like this:
>
> printf("<br>Total Value of Orders: $%01.2f<br>", $sum_value);[/color]

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
--
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.