警告,“ number_format()期望参数1为双精度,给定字符串 [英] warning, "number_format() expects parameter 1 to be double, string given
本文介绍了警告,“ number_format()期望参数1为双精度,给定字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从此行收到此错误,谁能告诉我谁可以解决此问题。
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;
}
推荐答案
从您的变量名称中,您正在向此函数传递字符串,但是如消息所示, number_format()
需要 double
。
Judging by your variable names you're passing a string into this function, but as the message says, number_format()
requires a double
.
您可以通过添加
$str = floatval($str);
作为函数的第一行。
这假设您的 $ str
变量包含可以强制为 double
的变量。如果不是这样,您可能会看到其他错误。
This assumes that your $str
variable contains something that can be coerced to a double
. If it doesn't you might see other errors.
这篇关于警告,“ number_format()期望参数1为双精度,给定字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文