argument must be greater then 0 - how is this possible when the value is greater then 0

php

Solution

`$` is used in `printf` format strings to specify which argument to print with the specifier after it, e.g.

sprintf('%2$f %1$d', $var1, $var2);

means it will display `$var2` as a float and then `$var1` as an integer.

You have `$` in your format string, but there's no number before it. So the number isn't greater than 0.

If you explain what you're trying to accomplish with that format string, I can update the answer with the correct way to do it.

If you're just trying to put a `$` before the price, it needs to be before the `%`, not after it.

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

Problem

So I am doing the following in PHP: ``` $cost = $this->reportDataStructure['ext_cost'] / $this->reportDataStructure['quantity']; var_dump($cost); // Outputs: float(220) $this->reportDataStructure['cost'] = sprintf("%$.2f", $cost); ``` And I keep getting ``` 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 ``` which pertains to the line: ``` $this->reportDataStructure['cost'] = sprintf("%$.2f", $cost); ``` But as we can see: ``` var_dump($cost); // Outputs: float(220) ``` So whats going on?

Original source

Related problems