Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 参数必须大于0-当值大于0时,这怎么可能_Php - Fatal编程技术网

Php 参数必须大于0-当值大于0时,这怎么可能

Php 参数必须大于0-当值大于0时,这怎么可能,php,Php,因此,我在PHP中执行以下操作: $cost = $this->reportDataStructure['ext_cost'] / $this->reportDataStructure['quantity']; var_dump($cost); // Outputs: float(220) $this->reportDataStructure['cost'] = sprintf("%$.2f", $cost); 我一直在 Warning: sprintf(): Argumen

因此,我在PHP中执行以下操作:

$cost = $this->reportDataStructure['ext_cost'] / $this->reportDataStructure['quantity'];
var_dump($cost); // Outputs: float(220)
$this->reportDataStructure['cost'] = sprintf("%$.2f", $cost);
我一直在

Warning: sprintf(): Argument number must be greater than zero in C:\xampp\htdocs\rms\site\web\module\Report\controller\InventoryReport.controller.php on line 98
与生产线相关的:

$this->reportDataStructure['cost'] = sprintf("%$.2f", $cost);
但我们可以看到:

var_dump($cost); // Outputs: float(220)

那么这是怎么回事?

$
printf
格式字符串中使用,以指定要打印的参数及其后面的说明符,例如

sprintf('%2$f %1$d', $var1, $var2);
表示它将以浮点形式显示
$var2
,然后以整数形式显示
$var1

格式字符串中有
$
,但前面没有数字。所以这个数字不大于0

如果你解释一下你想用这个格式字符串完成什么,我可以用正确的方法更新答案

如果你只是想把一个
$
放在价格之前,它需要放在
%
之前,而不是后面

$this->reportDataStructure['cost'] = sprintf("$%.2f", $cost);

我很幸运。直到今天早上我读到这个问题,我才知道这个
sprintf
功能: