1,105,288 Community Members

Format Number as percentage.

Member Avatar
Stick
Newbie Poster
20 posts since Feb 2005
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
RamiroS
Junior Poster in Training
57 posts since Mar 2005
Reputation Points: 0 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 

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..

...
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 -
   
}
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article