This question has been flagged
6 Replies
20642 Views

Hi I have a float filed and if the value is 2.17 I want to round up to 3. So always round up 1?

I cant comment but below will not work becasue I only want to round up. Below will round up and down. I belive I need to use math.ceil 
but cant find any examples


from odoo.tools import float_round
round(field_name
Avatar
Discard

But it’s working for me like when value is 3.45 than it’s show 3 and if value js 3.51 than it will be show 4

Hello. Did you solved? how you did it? i want to print values rounded up (ceiling) but I don´t know how to do it. In my case is just for PDF purpouses. Thanks

Best Answer

Hello Jay Roy,

You can try below code i think it's help you.

from odoo.tools import float_round
round(field_name)
Avatar
Discard
Best Answer

Hi Jay Roy,

You just need to do simple things which is giving odoo default.
This is a better way of doing it than hard coding as I can change the decimals to any figure from Odoo GUI under

 Technical >> Database Structure >> Decimal Accuracy >>
Change Digits 0 instead of 2 or 3.


Ex. Before Quantity display: 1.00 or 1.000

       After Quantity display: 1

Thanks.

Avatar
Discard
Best Answer

You can do like this in qweb

<p><t t-esc="round(6.2/9,2)"/></p>

Avatar
Discard
Best Answer

Hey try this 

x = 2.1

y = float(int(round(x)))

print x,y

if x > y:

        x = y+1

        print x,y

elif x == y:

        pass

Avatar
Discard
Author Best Answer

 I always want to want to round up. So 3.45 will become 4.

3.1 will be 4.

7.1 will be 8

Always up to the next never down. I read somewhere I need to be using math.ceil. reading up on that now
I also seen below trying to figure out how to use it though. I tried

from openerp.tools.float_utils  import float_round 

rolls_required = fields.float_round("Rolls Required", precision_digits=1, rounding_method='UP')

But I get TypeError: unsupported operand type(s) for /: 'str' and 'float'


// function for rounding numbers
from openerp.tools.float_utils import float_round // importing
// value - float number
// precision_digits - number of fractional digits to round to
// precision_rounding - decimal number representing the minimum non-zero value at the desired precision
// rounding_method - can be 'HALF-UP' or 'UP'
value1 = float_round(10.005, precision_digits=2, precision_rounding=None, rounding_method='HALF-UP')
value2 = float_round(10.005, precision_digits=None, precision_rounding=2, rounding_method='HALF-UP')
value3 = float_round(10.005, precision_digits=2, precision_rounding=None, rounding_method='UP')
value4 = float_round(10.005, precision_digits=None, precision_rounding=2, rounding_method='UP')
Avatar
Discard