Why do prices (or other fields with float values) sometimes display long decimal numbers like 19.9900000000001 instead of rounding to the nearest cent?

Why do prices (or other fields with float values) sometimes display long decimal numbers like 19.9900000000001 instead of rounding to the nearest cent?

The issue with product prices displaying excessive decimal places is a result of how computers handle floating-point arithmetic. Computers employ binary representation to store decimal numbers, which can occasionally lead to small rounding errors during calculations.

There is no straightforward way to handle this situation, but we suggest the following.

Go to the Odoo and open the label you need to fix. There will be a button (available in debug mode only):

After going to label view you need to find field with price and change it like this (highlighted block):

Here is a change:

Original:

<t t-esc="doc.list_price" />

Updated:

<t t-esc="doc.list_price" t-options="{'widget': 'float', 'precision': 2}"/> 

Please note that you need to repeat these steps every time you click “Update in Odoo” button while editing label in our Designer:

We are working on a way to simplify this feature but there is no another way for now.

Related Posts
Leave a Reply

Your email address will not be published.Required fields are marked *