0

I'm trying to add a price field into a custom entity I've created but the digit disapeared and it's rounded.

How to keep 2 digits ?

                    ->addColumn(
                        'price_ht',
                        Table::TYPE_FLOAT,
                        null,
                        [
                            Table::OPTION_SCALE => 2
                        ],
                        'Price HT'
                    );

This is interpreted as 10,0 in the database instead of (10,2) which would accept digits i guess so the scale option doesn't work.

This is what I have in my form

    <field name="price_ht">
        <settings>
            <validation>
                <rule name="required-entry" xsi:type="boolean">true</rule>
            </validation>
        </settings>
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="dataType" xsi:type="string">Magento\Catalog\Ui\Component\Listing\Columns\Price</item>
                <item name="label" xsi:type="string" translate="true">Price HT</item>
                <item name="formElement" xsi:type="string">input</item>
                <item name="source" xsi:type="string">entity</item>
                <item name="dataScope" xsi:type="string">price_ht</item>
            </item>
        </argument>
    </field>

And this is what I have in my listing

    <column name="price_ht">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="filter" xsi:type="string">text</item>
                <item name="label" xsi:type="string" translate="true">Price HT</item>
            </item>
        </argument>
    </column>

EDIT : Tried to add precision and same result

                    ->addColumn(
                        'price_ht',
                        Table::TYPE_FLOAT,
                        null,
                        [
                            Table::OPTION_SCALE => 2,
                            Table::OPTION_PRECISION => 2
                        ],
                        'Price HT'
                    );
2
  • Did you try to set the precision along with the scale as well? Feb 25 at 19:52
  • @ChristophFarnleitner Looks like same resultentering 4.750 result in the value 5
    – Claims
    Feb 28 at 8:47

1 Answer 1

1

Try precision because scale provide the number of digits after the decimal in a real data type.

Check the below link -

https://devdocs.magento.com/guides/v2.3/extension-dev-guide/declarative-schema/db-schema.html

2
  • just tried it seems not to work
    – Claims
    Feb 28 at 8:46
  • End up going threw all taht changing the type from float to decimal AND changing the precision to 10 instead of 2 (miss read the doc).
    – Claims
    Feb 28 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.