以下代码产生此错误:
警告:number_format() 期望参数 1 为双精度,字符串在/home/as1609/public_html/branchscreen/search.php 第 154 行给出
if (in_array($field, ['c', 'w', 'x', 'ad', 'ae', 'af', 'ag', 'ah', 'ai', 'aj', 'ak', 'al', 'am', 'an', 'ao', 'ap', 'aq', 'bd', 'be', 'br', 'bu', 'bx', 'by']) && $item[$field] > 999) {
$item[$field] = number_format($item[$field], 0, '.', ',');
知道为什么吗?
number_format() 函数的第一个参数需要一个浮点类型变量。
尝试像这样转换参数:(float)$item[$field]
$field='x';
$item[$field]='2929.69';
if (in_array($field, ['c', 'w', 'x', 'ad', 'ae', 'af', 'ag', 'ah', 'ai', 'aj', 'ak', 'al', 'am', 'an', 'ao', 'ap', 'aq', 'bd', 'be', 'br', 'bu', 'bx', 'by']) && $item[$field] > 999) {
echo $item[$field] = number_format((float)$item[$field], 0, '.', ',');
}
您可能有一些空格或 ,而不是 。(浮点)将解析正确的方式
您正在尝试将字符串格式化为数字,这将不起作用。
您能否发布$item['c']
的值,以便我们可以看到我们将看到什么样的数据?
或者更好的是,发布$item
的值。