|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
formatting output when using ECHO
Can someone help me with a simple(?) problem please?
The problem is that I calculate 600.00 + 250.00 and when I display the result, I see 450 I want to see 450.00 How can I format the value of a variable when using ECHO? Here is a more specific example: I am connecting to a mysql table and selecting a recordset based on dates entered by the user. I then store the data in arrays and close the connection. At this point I perform various calculations based on user preferences. I perform simple calculations like this: for ($k = 0; $k<=$count0; $k++) { $TotalNet = $TotalNet +$arNet[$k]; $TotalComm = $TotalComm +$arCommision[$k]; $TotalVAT = $TotalVAT +$arVAT[$k]; } Then I try to display the results like this: <table width="477" border="1"> <tr bgcolor="#99FFFF"> <td width="324"><div align="right">Totals:</div></td> <td width="39"><?php echo ("$TotalNet")?></td> <td width="53"><?php echo ("$TotalComm")?></td> <td width="33"><?php echo ("$TotalVAT")?></td> </tr> </table> etc. etc. What am I doing wrong? The actual values picked up from the mysql table are 400.00 and 250.00 Thanks! |
|
#2
|
|||
|
|||
|
RE: formatting output when using ECHO
Two ways you can do this...use printf:
printf ("%.2f",$TotalNet); or number_format: echo number_format($TotalNet, 2); |
|
#3
|
|||
|
|||
|
RE: formatting output when using ECHO
geee. there is am easy way to do that... :S
|
|
#4
|
|||
|
|||
|
RE: formatting output when using ECHO
Thanks for the help! I tried Matt's solution and it is working perfectly. I will try the :S suggestion as well.
|
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > formatting output when using ECHO |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|