warning, "number_format() expects parameter 1 to be double, string given

风格不统一 提交于 2020-01-17 14:46:10

问题


I get this error from this line can anyone tell me who can resolve this problem.

function format_numeric($str) {

    if(empty($str) && $str!=0) return;
    global $appearance_settings;
    $decimals = $appearance_settings['number_format_decimals'];
    $point = $appearance_settings['number_format_point'];
    $th_separator = $appearance_settings['number_format_separator'];
    $result = number_format($str, $decimals, $point, $th_separator); //THIS IS THE LINE WITH THE ERROR
    return $result;

}

回答1:


Judging by your variable names you're passing a string into this function, but as the message says, number_format() requires a double.

You can force the issue by adding

$str = floatval($str);

as the first line of your function.

This assumes that your $str variable contains something that can be coerced to a double. If it doesn't you might see other errors.



来源:https://stackoverflow.com/questions/24642812/warning-number-format-expects-parameter-1-to-be-double-string-given

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!