我在做一财务系统 当一笔单据收款时, (应收金额-实收金额=未收金额) 现在出现的问题找不到原因 应收金额1980,实收金额1980 那么未收的就是0 却出现科学计数法字样例如:2.27636307898909E-13 。 谁还遇到过这样的问题,可以讲一下原因
public void MakeValues() { Model.ReceivablesInfo info = new Model.ReceivablesInfo(); info.AID = Request.QueryString["aid"].ToString(); DAL.ReceivablesDAL dal = new DAL.ReceivablesDAL(); info = dal.QueryByPK(info); UnpaidSum.Text = DAL.Person.GetNotPay(info.AOrderID);//绑定的未收 txt_aReceivableNo.Text = info.aReceivableNo.ToString();//绑定收款单号 aOrderID.Text = info.AOrderID;//销售单号 aRealSum.Text = info.ARealSum.ToString();//实收金额 aReceivablesDate.Text = info.AReceivablesDate;//收款日期 aRemarks.Text = info.ARemarks;//备注 aShouldSum.Text = info.AShouldSum.ToString();//应付金额 //会计科目 (aMaker.FindControl("TextBox1") as TextBox).Text = info.AMaker; (aCustomer.FindControl("TextBox1") as TextBox).Text = info.ACustomer; (aCustomer.FindControl("Label1") as Label).Text = info.ACustomerID; } /// <summary> /// 得到未收款 /// </summary> /// <param name="str">销售订单号</param> /// <returns>未收金额</returns> static public string GetNotPay(string str) { if(str.Trim().Length==0) { return "0"; } //货物列表 OutputDepotSonDAL sdal = new OutputDepotSonDAL(); List<OutputDepotSonInfo> slist = new List<OutputDepotSonInfo>(); //收款单 ReceivablesDAL rdal = new ReceivablesDAL(); List<ReceivablesInfo> rlist = new List<ReceivablesInfo>(); //回款 GoodsBackPayDAL gdal = new GoodsBackPayDAL(); List<GoodsBackPayInfo> glist = new List<GoodsBackPayInfo>(); double sellsum = 0.0;//收款总额 slist = sdal.QueryByKeyWord().Where(s=>s.AOrderID==str).ToList(); foreach (OutputDepotSonInfo item in slist) { double a = double.Parse(item.AAmount); double r = double.Parse(item.AISReturn); double p = double.Parse(item.ARealPrice); sellsum += (a - r) * p; } double recesum = 0.0;//收款单总额 rlist = rdal.QueryByKeyWord().Where(s => s.AOrderID == str).ToList(); foreach (ReceivablesInfo item in rlist) { recesum += (double)(item.ARealSum); } double bcsum = 0.0;//回款记录总额 glist = gdal.QueryByKeyWord(); List<GoodsBackPayInfo> blist = new List<GoodsBackPayInfo>(); foreach (OutputDepotSonInfo item in slist) { foreach (GoodsBackPayInfo good in glist) { if (good.Aid==item.AID) { blist.Add(good); } } } foreach (GoodsBackPayInfo good in blist) { bcsum += double.Parse(good.ARealSum); } return (sellsum - recesum - bcsum).ToString(); }
这个问题很好查,你得分清楚变量的值和显示的值。
很明显,你这里是显示0.0D的错误。
个人感觉调试更改还是比较容易的。只是这个错误是昨天去客户那演示时出的问题,而在自己的机子上没有,所以从今天早上开始到现在一直不知道怎么去改动修正这支程序
@叶木木: 说了半天,你还是不明白,我简单点说吧,你把显示为科学计数法的截图贴出来。
@程序猿.码农: 我又猜测出一个你忽略的问题,浮点比较大小的时候,我们都是以差值小于一个常数来确定的。所以,我怀疑你的两个操作数并不等于 1980 。