number_format() generates error only in Return

Asked

Viewed 79 times

1

Inside the table orders, I have a field valor defined as decimal(10,2).

In the archive Order.php, I created a method to format the value:

public function getValorAttribute($valor)
{
    Log::debug($valor); // retorna 2423.42
    Log::debug(number_format($valor, 2, ',', '.')); // retorna 2.423,42
    return $this->attributes['valor'] = number_format($valor, 2, ',', '.'); // retorna erro
}

The problem is that Return is generating the error below, while the second debug() returns the formatted value:

A non well Formed Numeric value encountered

1 answer

1


Browser other questions tagged

You are not signed in. Login or sign up in order to post.