944,068 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 37514
  • PHP RSS
Mar 16th, 2005
0

Format Number as percentage.

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Stick is offline Offline
20 posts
since Feb 2005
Mar 16th, 2005
0

Re: Format Number as percentage.

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]
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
RamiroS is offline Offline
57 posts
since Mar 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: php help
Next Thread in PHP Forum Timeline: php rewrite question





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC