number formatting - PHP number_format not working properly -
i have variable:
$out .= $indent . sprintf("{$total_space}%-{$column_total}s{$space}%{$price_width}s$newline", ___('tax'), am_currency::render($this->{$prefix . '_tax'}, $this->currency));
which time being equals 4000. need formatted this: 4,000 changed code below:
$out .= $indent . sprintf("{$total_space}%-{$column_total}s{$space}%{$price_width}s$newline", ___('tax'), am_currency::render(number_format($this->{$prefix . '_tax'}), $this->currency));
however, dont know why 4 instead. happened other zeros? tried different values such 1214.92 example , in cases output leaves out last 3 digits.
this render function:
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); }
i tried changing code above this:
return sprintf($format, number_format($this->value), $this->currency);
but didnt work either. can please tell me whats wrong? blowing mind!
thank you.
your sprintf
format overriding number_format
function...it doesn't make sense use both @ same time (at least not same number within string). if use number_format
you'll see formats correctly.
i'd recommend using money_format
function instead, e.g.:
//money format setlocale(lc_monetary, 'en_us'); ... return money_format('%.2n', $this->value);
Comments
Post a Comment