PHP数字格式无法正常工作

PHP数字格式无法正常工作,php,number-formatting,Php,Number Formatting,我有一个变量: $out .= $indent . sprintf("{$total_space}%-{$column_total}s{$space}%{$price_width}s$newline", ___('Tax'), Am_Currency::render($this->{$prefix . '_tax'}, $this->currency)); 目前相当于4000。我需要它的格式如下:4000,所以我更改了我的代码如下: $out .= $indent . sprint

我有一个变量:

$out .= $indent . sprintf("{$total_space}%-{$column_total}s{$space}%{$price_width}s$newline", ___('Tax'), Am_Currency::render($this->{$prefix . '_tax'}, $this->currency));
目前相当于4000。我需要它的格式如下:4000,所以我更改了我的代码如下:

$out .= $indent . sprintf("{$total_space}%-{$column_total}s{$space}%{$price_width}s$newline", ___('Tax'), Am_Currency::render(number_format($this->{$prefix . '_tax'}), $this->currency));
然而,我不知道为什么,但是我得到了4。其他零发生了什么?我尝试使用不同的值,例如1214.92,在所有情况下,输出都会省略最后3位数字

这是渲染函数:

static function render($value, $currency = null, $locale = null)
    {
        return (string)self::create($value, $currency, $locale);
    } 

 public function __toString()
    {
        $format = array_key_exists($this->currency, $this->formats) ? 
            $this->formats[$this->currency] :
            '%.2f %s';
        return sprintf($format, $this->value, $this->currency);
    }
我甚至尝试过这样修改上面的代码:

        return sprintf($format, number_format($this->value), $this->currency);
但它也不起作用。你能告诉我怎么了吗?这真让我大吃一惊


谢谢。

您的
sprintf
格式正在覆盖您的
number\u格式
函数……同时使用这两种格式没有任何意义(至少对于字符串中的同一个数字没有意义)。如果您单独使用
number\u格式
,您会发现它格式正确

我建议改用
money\u format
功能,例如:

//money format
setlocale(LC_MONETARY, 'en_US');
...
return money_format('%.2n', $this->value);