警告:number_format()期望参数1为double,给定字符串

时间:2014-07-23 09:32:07

标签: php wordpress

我的页面滑块上出现此错误:

  

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

<?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 '';
}

3 个答案:

答案 0 :(得分:18)

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

使用(float)来解析正确的方法

答案 1 :(得分:2)

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

只是做:

var_dump($fields['price']);

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

答案 2 :(得分:0)

使用define other variabel修复它。

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

$tot2=$tot*1;
$vat=number_format($tot2*10/100,2);

也许帮助