# Weird behavior using pow() on a float function field

**URL:** https://discuss.tryton.org/t/weird-behavior-using-pow-on-a-float-function-field/3221
**Category:** Developer
**Created:** [September 16, 2020, 4:39am UTC](https://discuss.tryton.org/t/weird-behavior-using-pow-on-a-float-function-field/3221 "2020-09-16T04:39:48Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![fransuar](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/f/59ef9b/32.png) [@fransuar](https://discuss.tryton.org/u/fransuar)
#### Post date: [September 16, 2020, 4:39am UTC](https://discuss.tryton.org/t/weird-behavior-using-pow-on-a-float-function-field/3221/1 "2020-09-16T04:39:48Z")

</div>

Hi everyone,  
I am having a weird behavior on a float function field.

I define the following fields

```
weight = fields.Float('Weight', digits=(3,2),help='Weight in kilos')    
height = fields.Float('Height', digits=(3,1), help='Height in centimeters')    
bmi = fields.Function(
    fields.Float('BMI', digits=(2,2),help='Body mass index'), 'get_bmi')

def get_bmi(self, name):
    bmi = 0
    if self.height:
        bmi =(self.weight / pow((self.height/100),2))
    return bmi

```

Each time I want to change the view or close the tab tryton ask me to save the record even if it is already saved.

When I took off the pow function, for example, making bmi = self.weight/self.height, the problem is gone.

I am using tryton 5.0.

I don’t know if it is a bug or maybe I corrupted somthing on the db  
Regards.  
Francisco

---

<div class="post-metadata">

### Author: ![oscarQ](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/oscarq/32/413_2.png) [@oscarQ](https://discuss.tryton.org/u/oscarQ)
#### Post date: [September 16, 2020, 5:55am UTC](https://discuss.tryton.org/t/weird-behavior-using-pow-on-a-float-function-field/3221/2 "2020-09-16T05:55:39Z")

</div>

Hi Francisco,

I think that the problem is that in some case you have to be returning a number that have more digits that the ones you defined for the field (2,2).

---

<div class="post-metadata">

### Author: ![fransuar](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/f/59ef9b/32.png) [@fransuar](https://discuss.tryton.org/u/fransuar)
#### Post date: [September 16, 2020, 5:56pm UTC](https://discuss.tryton.org/t/weird-behavior-using-pow-on-a-float-function-field/3221/3 "2020-09-16T17:56:36Z")

</div>

Thank you very much OscarQ. Your answer helps me to solve this problem

On the getter, it has to return a rounded floating number using the round function

```auto
def get_bmi(self, name):
    bmi = 0
    if self.height:
        bmi =(self.weight / pow((self.height/100),2))
        bmi = round(bmi,3)
    return bmi

```

This is the solution

---

<div class="post-metadata">

### Author: ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)
#### Post date: [October 16, 2020, 5:56pm UTC](https://discuss.tryton.org/t/weird-behavior-using-pow-on-a-float-function-field/3221/4 "2020-10-16T17:56:41Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
