Format Number as percentage.

Reply

Join Date: Feb 2005
Posts: 20
Reputation: Stick is an unknown quantity at this point 
Solved Threads: 0
Stick Stick is offline Offline
Newbie Poster

Format Number as percentage.

 
0
  #1
Mar 16th, 2005
I have a web page that prints a number from a mysql database.
Can anyone tell me how to show this number as a percent?
Does it need to be formated that way in the database table? or
Can I format it that way using the printf function at the page?
Thanks in advance for any help!
Stick
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 48
Reputation: RamiroS is an unknown quantity at this point 
Solved Threads: 0
RamiroS's Avatar
RamiroS RamiroS is offline Offline
Light Poster

Re: Format Number as percentage.

 
0
  #2
Mar 16th, 2005
What I normally do is: if the number is a percentage you can print it directly or make the calculation with PHP... or (read below) create a function). Depending the case I don't know about any MySQL function to do this..
[php]
...
function perc($num) {
return format_number($num,2)." %";
}
$data=mysql_fetch_object($sql)) {
print $data->perc . " %"; # Example A
print (($data->percn*$data->total)/100); # Example B
print perc($data->perc); # Example C - using a function and some extra format -

}
[/php]
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC