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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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? |
|
|||
|
> $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 |
|
|||
|
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 |
|
|||
|
*** 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 -- |