# Misunderstanding why when i put "0" in a float field it doesn't work normally

**URL:** https://discuss.tryton.org/t/misunderstanding-why-when-i-put-0-in-a-float-field-it-doesnt-work-normally/4332
**Category:** Developer
**Created:** [June 18, 2021, 10:44am UTC](https://discuss.tryton.org/t/misunderstanding-why-when-i-put-0-in-a-float-field-it-doesnt-work-normally/4332 "2021-06-18T10:44:39Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![aso](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/a/f04885/32.png) [@aso](https://discuss.tryton.org/u/aso)
#### Post date: [June 18, 2021, 10:44am UTC](https://discuss.tryton.org/t/misunderstanding-why-when-i-put-0-in-a-float-field-it-doesnt-work-normally/4332/1 "2021-06-18T10:44:39Z")

</div>

Hi am trying to understand something , i have a field type float and i want to display a sentence if i put “0” , it works with all numbers under 0 and after 0 but not with “0”  
is it normal with tryton , is their a problem with using 0 with tryton

```auto
diameter = fields.Float("Diameter ")

@fields.depends('diameter', 'art')
def on_change_with_diameter_arts(self, name=None):
    if (self.diameter == 0 and self.art == "carpentry" ):
        return " No carpentry "

```

but nothing display when i put “0” in the field “diameter” , it doesn’t work just when i make “0” in field but in other conditions and with other number it works normally !

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [June 18, 2021, 12:01pm UTC](https://discuss.tryton.org/t/misunderstanding-why-when-i-put-0-in-a-float-field-it-doesnt-work-normally/4332/2 "2021-06-18T12:01:48Z")

</div>

I guess you have to debug to see what is the value of `diameter` and why your test is not working.

---

<div class="post-metadata">

### Author: ![rvong](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/r/3bc359/32.png) [@rvong](https://discuss.tryton.org/u/rvong)
#### Post date: [June 18, 2021, 1:44pm UTC](https://discuss.tryton.org/t/misunderstanding-why-when-i-put-0-in-a-float-field-it-doesnt-work-normally/4332/3 "2021-06-18T13:44:11Z")

</div>

Something is not right with your **on\_change\_with** name function. Are you trying to have the field **art** display the value **No carpentry** based on the value of the diameter? If so then your **on\_change\_with** function should be named correctly to:

`
def on_change_with_art(self, name=None)
`

The naming convention for **on\_change\_** and **on\_change\_with\_** is very critical for it to work.

---

<div class="post-metadata">

### Author: ![aso](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/a/f04885/32.png) [@aso](https://discuss.tryton.org/u/aso)
#### Post date: [June 18, 2021, 2:11pm UTC](https://discuss.tryton.org/t/misunderstanding-why-when-i-put-0-in-a-float-field-it-doesnt-work-normally/4332/4 "2021-06-18T14:11:56Z")

</div>

Hi , No am trying to display in the field" ```  
diameter\_arts

" the value returned by the function on\_change\_with\_diameter\_arts ,  
when i tried to work in debug mode like M. @ced advice me, there was an error shown for the first time :

# float() argument must be a string or a number, not 'NoneType

---

<div class="post-metadata">

### Author: ![rvong](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/r/3bc359/32.png) [@rvong](https://discuss.tryton.org/u/rvong)
#### Post date: [June 18, 2021, 2:18pm UTC](https://discuss.tryton.org/t/misunderstanding-why-when-i-put-0-in-a-float-field-it-doesnt-work-normally/4332/5 "2021-06-18T14:18:49Z")

</div>

I see, well, I guessed wrong.  
In that case, depending on how and where your form is displayed, the **NoneType** problem maybe due to the lack of a default value for the field **diameter**. Have you tried putting a

`
def default_diameter(self):
    return 0
`

and see if that fixes your problem?

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [June 18, 2021, 3:03pm UTC](https://discuss.tryton.org/t/misunderstanding-why-when-i-put-0-in-a-float-field-it-doesnt-work-normally/4332/6 "2021-06-18T15:03:53Z")

</div>

You must always in `on_change` functions support the possibility that the value is `None` (even if required).
