Parameter error

-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!

    
asked by anonymous 13.04.2018 / 03:10

1 answer

1

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

Casting the value passed by parameter to float should resolve 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; }
}
    
13.04.2018 / 03:36