28

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...

Arnaud Le Blanc
  • 98,321
  • 23
  • 206
  • 194
Tool
  • 12,126
  • 15
  • 70
  • 120

3 Answers3

37

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.

Boschman
  • 825
  • 1
  • 10
  • 17
kgilden
  • 10,336
  • 3
  • 50
  • 48
12

in the *.yml

curr_price:
    type: decimal
    precision: 10
    scale: 2
Community
  • 1
  • 1
juan
  • 365
  • 4
  • 10
10
/**
 * @ORM\Column(type="float", scale=2)
 */
protected $curr_price;

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

Dan Esparza
  • 28,047
  • 29
  • 99
  • 127
Serhii Polishchuk
  • 1,442
  • 17
  • 22
  • 2
    According to [docs](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/basic-mapping.html#property-mapping): *scale: (optional, default 0) The scale for a decimal (exact numeric) column (**applies only for decimal column**), which represents the number of digits to the right of the decimal point and must not be greater than precision.* – Martin Janeček Jun 11 '15 at 08:25