| | |
Format Number as percentage.
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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]
[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]
![]() |
Similar Threads
- Number to a percentage (C++)
- How to format number? (Visual Basic 4 / 5 / 6)
- Big binary String to a number format (Java)
- Format Number (VB.NET)
- Newbie question (C)
- round off number (C)
Other Threads in the PHP Forum
- Previous Thread: php help
- Next Thread: php rewrite question
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class clean cms code countingeverycharactersfromastring crack cron curl database date directory display download dynamic echo email error fairness file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail match menu mlm mod_rewrite multiple mysql oop pageing pagerank parse paypal pdf php printer problem query radio random recursion regex remote script search server sessions simple sms soap source space spam sql structure syntax system table tutorial update upload url validation validator variable video web xml youtube





