Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
5638 Lượt xem

Hi friends,

I'm facing a problem on float subtraction.When subtracting value of 10000.00 from 10000.00 we supposed to get 0, but here in openerp i get a balance value of

-1.81898940355e-12 when displaying balance using below code:

bal+=j_line.debit-j_line.credit

here, i have used a line of code for setting up 2 digits after decimal(like 123.00), i have given a line of code which i used to display:

lin_bal=bal if bal!=0.00 else 0.00 

lin_deci_bal= "%0.2f" % lin_bal

it displays output as -0.00,instead i need output as 0.00

So please suggest some solution to resolve this problem. I have taken lot of time working on this issues. Kindly help me solve this.Thanks in advance.
 

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi Vadivel,

Just for reference, I am not sure below code work in version 7.

Using below code I fixed my issue in version 10.0 

from odoo.tools.float_utils import float_round

precision = self.env.user.company_id.currency_id.decimal_places

bal+= float_round(j_line.debit-j_line.credit, precision_digits=precision)

Best Thanks,
Ankit H Gandhi.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 5 22
34145
0
thg 3 19
4183
0
thg 1 19
5247
4
thg 2 24
12492
0
thg 1 18
4021