0
I have an IMDB (Internet Movie Data Base) number, in case the number is 7.7 out of 10. I need to put this number on a scale from 0 to 5 (integers only). On the basis of this reply: https://stackoverflow.com/a/10201086/1844007
I used:
$res = ($obj->imdbRating / 100) * 5;
Only the results are: 0.385 which is not the actual note of the film(7.7).
What I’m doing wrong?
Complete code corrected with the help of Bonifazio:
function imdb($filme) {
$url = 'http://www.omdbapi.com/?i=&t=' . strtolower(str_replace(' ', '+', $filme));
$json = file_get_contents($url);
$obj = json_decode($json);
$res = round($obj->imdbRating / 2,0);
return $res;
}
Thank you very much.
Try
( $obj->imdbRating / 2 )
– MarceloBoni
You’re right, post your comment as reply I will mark as best response, thank you very much.
– sistematico
do not consider as an answer rs, your problem was only in mathematical calculus... I will add a rounding function that works right, then put as an answer
– MarceloBoni
I don’t know if I did it right:
round($obj->imdbRating / 2,0);
– sistematico