Skip to Content
Menu
This question has been flagged
3 Replies
2727 Views

I have a Float field:
`
​field_name = fields.Float(string='The percentage paid upon signing the contract', default=6.7)
`


When I apply this, it shown as 670

same for default=50.0       ---> 5000

25.5 ---> 2550

I want to show the default value as 6.7 and 50.0 and 25.5


How could I do this .. thanks!





Avatar
Discard
Best Answer

Hi,

Try this code:
field_name = fields.Float(string='The percentage paid upon signing the contract', default=6.7,digits=[1, 1])

Hope it helps

Avatar
Discard
Best Answer

Hi, 


I think you are using percentage widget in XML as below so the default value of 50.00 will be shown as 5000 and 6.7 will be shown as 670:

 <field name="field_name"  widget="percentage"/>


So to fix it, you can delete widget from XML or you can keep it and change the value as below:

For 50.00% should be 0.5 in python code and it will be shown as 50 %

For 6.7% should be 0.067 in python code and it will be shown as 6.7 %


Avatar
Discard
Best Answer

Hello @Muneeb Alalfi


field_name = fields.Float(string='The percentage paid upon signing the contract', default=6.7, digits=[1, 1])


Inside the float field, add an attribute called 'digits'.

As you need values ​​like this: 6.7 ----> 6.7, 50.0 ----> 50.0, 25.5 ----> 25.5

You have to add attribute : 'digits=[1,1]'

Here 1 is used for 1 digit after decimal point.

If 2 is used ie digits=[2,2], than your answer will be like this:

6.7 ----> 6.70, 50.0 ----> 50.00, 25.5 ----> 25.50


Hope this answer helps you.

Thanks & Regards,
Email:  odoo@aktivsoftware.com  

Skype: kalpeshmaheshwari

Avatar
Discard
Related Posts Replies Views Activity
3
May 25
1859
1
May 25
1466
1
Apr 25
2689
1
Apr 25
3468
1
Apr 25
1050