SunQuest
           PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
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  
Old September 2nd, 2002, 12:34 PM
cateyes cateyes is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Cyprus
Posts: 68 cateyes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
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!

Reply With Quote
  #2  
Old September 2nd, 2002, 03:13 PM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
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);


Reply With Quote
  #3  
Old September 2nd, 2002, 04:05 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: formatting output when using ECHO

geee. there is am easy way to do that... :S

Reply With Quote
  #4  
Old September 3rd, 2002, 09:57 AM
cateyes cateyes is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Cyprus
Posts: 68 cateyes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
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.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > formatting output when using ECHO


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway