Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine 2 - 2 decimal places on a float?

Annotation:

/**
 * @ORM\Column(type="float", scale="2")
 */
protected $curr_price;

I'm using it with Symfony 2.

And this field becomes a double in MySQL database instead of float with 2 point precision.

What am I doing wrong? I tried deleting the DB, reinserting etc...

like image 713
Tool Avatar asked Sep 03 '11 21:09

Tool


3 Answers

Both precision and scale properties work only with the decimal mapping type (link). I suggest you use the decimal type.

As to why it's creating a double field instead of float, I'm not entirely sure. It probably has to do with being compatible with all supported databases. I see no mention of double mapping type so I assume they use the same type for both.

like image 188
kgilden Avatar answered Oct 23 '22 22:10

kgilden


in the *.yml

curr_price:
    type: decimal
    precision: 10
    scale: 2
like image 23
juan Avatar answered Oct 23 '22 21:10

juan


/**
 * @ORM\Column(type="float", scale=2)
 */
protected $curr_price;

scale should be an integer, and you are using a string

like image 10
Serhii Polishchuk Avatar answered Oct 23 '22 23:10

Serhii Polishchuk