警告:number_format()期望参数1为双精度,给出字符串


Warning: number_format() expects parameter 1 to be double, string given

我在我的页面滑块上得到了这个错误:

警告:number_format()期望参数1为double,字符串在/home/globalar/public_html/wp-content/themes/automotive_s1/includes/slider.php第30行

<?php
    if $str = floatval($str); ($post->post_type == "gtcd") {
        the_title();
    if (isset( $fields['price'])) {
        echo ' | <span class="price_slider">'.'  '.$symbols['currency']; 
        echo number_format($fields['price']).'</span> ';
    } else { 
        echo '';
}
$fields['price']='8, 9858';
echo number_format((float)$fields['price']);

使用(float)解析正确方式

您应该检查$fields['price']内部的值。

只做:

var_dump($fields['price']);

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

通过定义其他变量来修复。

$tot=$row['total'];
$total=number_format($tot,2);
$tot2=$tot*1;
$vat=number_format($tot2*10/100,2);

也许帮助