General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 29th, 2003, 12:12 AM
nestorvaldez nestorvaldez is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 40 nestorvaldez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 21 sec
Reputation Power: 7
Formatting Field to numeric

How can I Format a numeric field, to be show in the web with the Commas,, Ex.. I have a numeric Field in MySql, the field is Amount and I declare it like Decimal 14,2.. I type the value 125000 in the field and when I print the value in the site, it is show without the numeric format, or currency... I want this so. : US $125,000.00, How can i do this...

I don't know if the type field is wrong...(decimal)

Reply With Quote
  #2  
Old September 29th, 2003, 02:42 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
PHP Code:
 number_format($num2); 
__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Reply With Quote
  #3  
Old September 30th, 2003, 11:19 PM
nestorvaldez nestorvaldez is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 40 nestorvaldez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 21 sec
Reputation Power: 7
<?
$host = "localhost";
$username = "mailcrea_than";
$password = "than";
$dbname = "mailcrea_loto";

$connection = mysql_connect("localhost", "mailcrea_than", "than");
$db = mysql_select_db("mailcrea_loto");

$resultado = mysql_query("SELECT lploto FROM parametros");// WHERE id = '1'");

$row = mysql_fetch_array($resultado);
while ($row) {
print "<table border=0>";
print "<td width=\"20%\">";
print "<div align=\"center\"><font color=\"0000ff\" face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"6\">";

// I WANT TO PRINT THIS VALUE FROM THE TABLE WITH THE COMMAS, BUT IT RETURN ME AN ERROR. HOW I CODE IT.. THE VALUE IS IN LPLOTO, IT IS A TABLE FIELD..

print ("$row[lploto]");
print "</font></div>";
print "</td>";
print "</tr>";
print "</table>";
$row = mysql_fetch_array($resultado);
}
?>

Reply With Quote
  #4  
Old October 1st, 2003, 01:29 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
PHP Code:
print $row['lploto']; 
Always quote your associative arrays.

Reply With Quote
  #5  
Old October 1st, 2003, 01:30 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
Also, you could have done this:
PHP Code:
print "${row['lploto']}"

Reply With Quote
  #6  
Old October 1st, 2003, 01:31 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
Or
PHP Code:
 printf("%s"$row['lploto']); 

Reply With Quote
  #7  
Old October 1st, 2003, 01:44 AM
nestorvaldez nestorvaldez is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 40 nestorvaldez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 21 sec
Reputation Power: 7
your code doesn't work ....
the lploto is a field of the table and it have this value "6000000.00" in this format, without the commas, and I want to print it with the commas...6,000,000.00, like this....
I use this code you gave me but, don't give me the commas, and I was trying to use the Format_number, in this way, but, it is wrong, because it return me an error.

print ("Format_number $row[lploto,2]");

Reply With Quote
  #8  
Old October 1st, 2003, 01:46 AM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 366 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 59 sec
Reputation Power: 7
PHP Code:
print( number_format$row['lploto'], ) ); 


try it this way.
__________________
-- Jason

Reply With Quote
  #9  
Old October 1st, 2003, 01:56 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
HA, now look who is quick... seems to be you Taelo.

Reply With Quote
  #10  
Old October 1st, 2003, 01:57 AM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 366 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 59 sec
Reputation Power: 7
haha,...I gotcha! :P

Reply With Quote
  #11  
Old October 1st, 2003, 02:09 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
Yeah, I can't keep up anymore

Reply With Quote
  #12  
Old October 1st, 2003, 12:02 PM
nestorvaldez nestorvaldez is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 40 nestorvaldez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 21 sec
Reputation Power: 7
what means this comments?

Reply With Quote
  #13  
Old October 1st, 2003, 01:49 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Nestorvaldez, you've copied the code incorrectly. You have:

PHP Code:
print ("Format_number $row[lploto,2]"); 


which prints a string. What you should have is:

PHP Code:
print( number_format$row['lploto'], ) ); 


which executes the function number_format() on the value $row['lploto'] and displays two decimal points. The rest of the thread was in reference to an earlier post in which laidbak responded very quickly to a thread Taelo was watching.

Try replacing your code with the exact code Taelo provided (and which I've pasted in here again) and see if that helps.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Formatting Field to numeric


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 |