Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
177 views
in Technique[技术] by (71.8m points)

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

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;

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...