skip to Main Content

I have a Symfony product entity mapped with Doctrine.

My column price is defined like that :

 /**
  * @ORMColumn(type="float", scale=2)
  */
 private $price;

In PhpMyAdmin, on one of my products, i define the price to be 59.99. But when i display it in my template i can’t have the entire number and i have only 59.
I tried doing this :


{{  product.price|number_format(2) }}

but it displays 59.00.. the dump gives me the same thing.

Does anyone have an idea ?

2

Answers


  1. Chosen as BEST ANSWER

    I found the solution thanks to @AlexandreTranchant, my product.price getter was like that

    public function getPrice(): ?int
    {
        return $this->price;
    }
    

    so it allowed me to store only integer and not float/decimal number. Changed it to float and I have my entire decimal number.


  2. Not sure why you loose the decimals but i prefer to use type decimal:

        /**
         * @ORMColumn(type="decimal", precision=10, scale=2)
         */
        private $price;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search