2
我嘗試計算persentage,且通過零顯示錯誤浮分裂,這是我的代碼Python的越來越被零除
d4 = float(self.qty_normal)+float(self.qty_abnormal)
d3 = float(self.qty_normal)+float(self.qty_recoveryabn)
if self.flag_recovery == False:
if self.qty_abnormal and self.qty_normal:
pnormal =(self.qty_normal)/float(d3)*(100.00)
pabnormal =(self.qty_abnormal)/float(d3)*(100.00)
self.nursery_persentagea = pabnormal
self.nursery_persentagen = pnormal
if self.flag_recovery == True:
if self.qty_recoveryabn and self.qty_normal:
pnormal =(self.qty_normal)/float(d3)*(100.00)
pabnormal =(self.qty_recoveryabn)/float(d3)*(100.00)
self.nursery_persentagea = pabnormal
self.nursery_persentagen = pnormal
幫助我解決這個
你不能把零分。只需在分割之前設置一次檢查,看看下半部分是否爲0。 – NSNoob