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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24906861/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:32:17  来源:igfitidea点击:

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

phpwordpress

提问by Odofin Caleb

I got this Error on my Page slider:

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

Warning: number_format() expects parameter 1 to be double, string given in /home/globalar/public_html/wp-content/themes/automotive_s1/includes/slider.php on line 30

警告: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 '';
}

采纳答案by Marcin Nabia?ek

You should check what value is inside $fields['price'].

你应该检查里面有什么值$fields['price']

Just do:

做就是了:

var_dump($fields['price']);

It's possible you have some spaces or ,instead of .

您可能有一些空格或,代替.

回答by Faruk Omar

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

use (float)to parse correct way

用于(float)解析正确的方式

回答by Muhammad eko kristanto

fix it with define other variabel.

用定义其他变量来修复它。

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

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

maybe help

也许有帮助