Parameter error

Asked

Viewed 39 times

-1

function tr_rating_format_number($id = NULL, $display = NULL) {

$return = number_format(get_post_meta($id, 'ratings_average', true), 1);
$return = get_post_meta($id, 'ratings_average', true) == '' ? '0.0' : $return;

if( $display == TRUE ) { echo $return;  }else{ return $return; }
}

Warning: number_format() expects Parameter 1 to be double, string Given in /home/moovseri/public_html/wp-content/themes/toroplay/inc/template-functions.php on line 434

Please help!

  • The error itself is telling the error rs.

1 answer

1

The error basically says that a string type value was passed in the first function parameter format_number where a double type value was expected.

Casting a value passed by parameter to float should already solve this warning.

function tr_rating_format_number($id = NULL, $display = NULL) {

$return = number_format((float)get_post_meta($id, 'ratings_average', true), 1);
$return = get_post_meta($id, 'ratings_average', true) == '' ? '0.0' : $return;

if( $display == TRUE ) { echo $return;  }else{ return $return; }
}
  • Thanks, it worked!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.