How to stop auto rounding of float fields in odoo - BOOKC -->

How to stop auto rounding of float fields in odoo

Tuesday, September 18, 2018

In this tutorial I am going to teach you how to stop auto rounding of Float fields in Odoo. Sometimes we need to store values in Float field like this (1.196). But the issue is when we write this (1.196) on Float field, the internal behaviour of Float fields will convert this value or round up this value into (1.20).



How to stop auto rounding of float fields in odoo

If we will save this it converts (1.196) to (1.20). So to overcome this issue we use "digits" parameter on Float field.

How to stop auto rounding of float fields in odoo

What is digits = (x, y)?

To define the precision and scale of the number we use digits parameter in Float fields. Now the question raise here what is precision and scale. The answer is precision is the total number of significant digit in the given number before and after the decimal point. And the scale is the number of digit after the decimal point. So you can say that digits = (12, 3), here you can increase the number 3 as per your need or requirement.


# From
rate = fields.Float()

# To
rate = fields.Float(digits=(12,3))     
 

How to stop auto rounding of float fields in odoo