Php 警告:number_format()要求参数1为双精度,字符串给定

Php 警告:number_format()要求参数1为双精度,字符串给定,php,wordpress,Php,Wordpress,我在页面滑块上遇到以下错误: 警告:number_format()要求参数1为双精度,字符串在第30行的/home/globalar/public_html/wp content/themes/automotive_s1/includes/slider.php中给出 您应该检查$fields['price']中的值 只要做: var_dump($fields['price']); 您可能有一些空格或,而不是用define other variabel修复它 $tot=$row['total']

我在页面滑块上遇到以下错误:

警告:number_format()要求参数1为双精度,字符串在第30行的/home/globalar/public_html/wp content/themes/automotive_s1/includes/slider.php中给出


您应该检查
$fields['price']
中的值

只要做:

var_dump($fields['price']);

您可能有一些空格或
而不是

用define other variabel修复它

$tot=$row['total'];
$total=number_format($tot,2);

$tot2=$tot*1;
$vat=number_format($tot2*10/100,2);
也许有帮助

$fields['price']='8, 9858';
echo number_format((float)$fields['price']);

使用
(float)
以正确的方式分析问题

您的问题到底是什么?PHP提供了一条详细的错误消息。方法
number\u format
要求第一个参数是double类型的标量,但变量
$fields['price']
包含一个字符串。如果它包含一个double,您可以将其强制转换。您不知道
警告的含义:number\u format()期望参数1为double,字符串给定
?无论如何,尝试强制转换
(float)$fields['price'])
当它需要一个双精度字符串时,您正在给
number\u format()
一个字符串。您的
$fields['price']
是一个双精度值。我认为您的格式值有误。。正如函数名所述,您需要设置数字的格式。。所以,您应该只传递一个未格式化的数字,尽管它很简单。。。比如1000或10000.0678。我认为你的变量有,关于它,你应该了解变量的数据类型。编码前务必阅读手册!谢谢Marcin,但我在这行的两个实例中都有$fields['price'],我是否应该在这两个实例中都转储($fields['price'])。新代码到底应该是什么样子的呢?在这段代码的开头你应该在
之后你应该在
之前我尝试过,但没有成功。我在
$fields['price']='8, 9858';
echo number_format((float)$fields['price']);