Connecting Tech Pros Worldwide Forums | Help | Site Map

Never liked printf, why is it doing this?

Bob
Guest
 
Posts: n/a
#1: Jul 17 '05
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?


Gordon Burditt
Guest
 
Posts: n/a
#2: Jul 17 '05

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
Chris Hope
Guest
 
Posts: n/a
#3: Jul 17 '05

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
Alvaro G Vicario
Guest
 
Posts: n/a
#4: Jul 17 '05

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