Write a PHP program to calculate percentage of total
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
In this exercise, let's assume that we have two variables: one is the number you wish to change into percentage and the other is total. In the given example, we have defined a new function cal_percentage() and taken two variables $num_amount and $num_total. Within this function, we have applied the mathematical formula of percentage calculation, i.e., divide the amount by the total amount and multiply the result by 100, so that we can opt a percentage. In the next line, we have used number_format() function that formats a number with grouped thousands.
PHP program to Calculate Percentage
Output of the above code -
need an explanation for this answer? contact us directly to get an explanation for this answerPercentage of 39 in 100 : 39% Percentage of 26 in 200 : 13% Percentage of 17 in 150 : 11% Percentage of 30 in 400 : 8% Percentage of 11 in 190 : 6%