title: How to convert NAN to 0 in php
body: <p>I am calculating percentages of values in a database table, however, when there is no values, the function returns NAN, i would like the function to return 0 instead, the function am using is:</p>
  
  <pre><code>function calculate_percentages($atts){         
      global $wpdb;
      $postid = get_the_ID();
      $myrate_name = "sql_table_name";
      $total_count = $wpdb-&gt;get_var( "SELECT SUM(rates) FROM $myrate_name WHERE post_id=$postid");
      $top = $wpdb-&gt;get_var( "SELECT SUM(rates) FROM $myrate_name WHERE  rating = 5 AND post_id=$postid");
      $top_avarage = round($top/$total_count*100);
      return $top_avarage;
  </code></pre>