Problem with the decimal data type in Doctrine2 and Symfony3

2

I have an entity that has three fields of decimal type

/**
     * @var decimal
     *
     * @ORM\Column(name="cantidad", type="decimal", precision = 3, scale=2)
     */
    private $cantidad;


    /**
     * @var decimal
     *
     * @ORM\Column(name="precio_cuc", type="decimal",precision = 3, scale=2)
     */
    private $precio_cuc;


    /**
     * @var decimal
     *
     * @ORM\Column(name="precio_cup", type="decimal",precision = 3 ,scale=2)
     */
    private $precio_cup;

In my Form that the entity manages, I have it declared like this .. I only put one ..the others are equal

->add('cantidad',NumberType::class,array(
                'scale' => 2,
            ))

but at the time of saving the entity in the BD the field approaches an integer .. if I enter 4.5 it approaches it to 5.. In the BD the fields are declared as decimal too ..

What is the error that I do not see?

    
asked by miguel angel martinez 20.07.2017 в 15:57
source

1 answer

0

The problem in these cases lies in the separator ("," or ".") depending on the locale configured in symfony, the intl library of PHP and the locale of Mysql

If in the form you put a point and it rounds you to integer test separating with comma. If separating with the comma also rounds you to integer then you will have to check all the locale.

If you only get an error with the point or with the comma, keep the following in mind:

9.988.776,65 € Europa
$9,988,776.65 EEUU

Change the locale that fails and you're done. Beware of the locale of the server itself and PHP

    
answered by 14.09.2017 в 00:02