您好,我在身份方面遇到问题。样本:availBudget = 1000.00和totBaseCost = 1000.01,它必须是UNBUDGETED,但我认为它只能得到整数。
totBaseCost = mbo.getDouble("TOTALBASECOST")
totBaseCost1 = "%.2f" % float(totBaseCost)
#totBaseCost1 = "%.2f" % totBaseCost
budgetSet = mbo.getMboSet("BUDGET")
availBudget = 0
if budgetSet is not None:
budgetMbo = budgetSet.getMbo(0)
totBudgetAmount = budgetMbo.getFloat("C1BUDTOTCOST")
estTotCost = budgetMbo.getMboSet("C1ESTTOTCOSE").sum("LINECOST")
comTotCost = budgetMbo.getMboSet("C1COMMITTED").sum("LINECOST")
actTotCost = budgetMbo.getMboSet("C1ACTTOTCOST").sum("LINECOST")
#Available Budget
availBudget = float(totBudgetAmount) - float(estTotCost) - float(comTotCost) - float(actTotCost)
availBudget = "%.3f" % availBudget
if availBudget < 0:
availBudget = abs(availBudget)
if (totBaseCost1) > availBudget and availBudget <> 0:
mbo.setValue("C1BUDGETSTATUS","",11L)
mbo.setValue("C1BUDGETSTATUS","UNBUDGETED",11L)
elif (totBaseCost1) <= availBudget:
mbo.setValue("C1BUDGETSTATUS","",11L)
mbo.setValue("C1BUDGETSTATUS","BUDGETED",11L)
elif str(totBaseCost1) == "0.00" and str(availBudget) <> "0.00":
mbo.setValue("C1BUDGETSTATUS","",11L)
mbo.setValue("C1BUDGETSTATUS","BUDGETED",11L)
答案 0 :(得分:0)
Python确实键入了强制,这可能是您的问题。如果您有0
(一个整数)的比较或分配,请尝试使用0.0
(一个浮点数)。
答案 1 :(得分:0)
使用psdi.util.MXMath类进行成本计算,因为它在后台使用BigDecimal。 请查看此entry,以了解不使用浮点数/双精度数进行货币计算的原因。
此外,正如Dex指出的那样,您应该在mboSet上使用isEmpty()方法来确定是否获取记录。