Search Here

How to stop auto rounding of float fields in odoo

In this article you will learn 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

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.

Read More: How to align left Odoo fields [float, integer] in tree views

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.
Read More: How to Add Domain Filter for Many2many Field in Odoo

# From
rate = fields.Float()

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

How to stop auto rounding of float fields in odoo

Post a Comment

6 Comments

  1. If I have a float field that is 2.17 how do I get it to go to next number 3?

    ReplyDelete
    Replies
    1. if your number is 2.57 than its roundup into 3. For more detail clear you math concepts.

      Delete
  2. Why are you not making new tutorials you are amazing teacher. A big shout-out to your team.

    ReplyDelete
    Replies
    1. Thanks for appreciating, we will do our best....

      Keep sharing keep learning

      Delete
  3. explaination is good , but how to avoid rounding in group by
    i am having scenario were my company currency is bhd, hence 3 decimals, i am not able to get this in pivot view and group by
    i am using odoo version 9

    ReplyDelete
    Replies
    1. can you place share screen shot using some online link

      Delete