dijkr / Copia

Laravel-project with CMS
0 stars 0 forks source link

Formatting of prices when they are add to the database #3

Open dijkr opened 1 year ago

dijkr commented 1 year ago

Prices are stored with datatype float. They however show every digit after the main numbers. And it won't show any zero's if the numbers after the main number end with a zero. It need to have two digits after the main number. 1,00 and 2,95.

dijkr commented 1 year ago

One solution to process it in the view: {{ '€' . ' ' . number_format($product->Price, 2) }} This works, and it also makes sure that any mistake in the retrieval from prices would be corrected.

dijkr commented 1 year ago

Still need a solution to automatically process the price at retrieval. Should it be done at the model or the controller. This should work:

public function formattedPrice() { return number_format($this->price, 2); }