本文介绍了价值在Zero之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里在下面的代码EstbFee = 0.00和FutureEstbFee = 4000.10但是当我试图添加这两个时它导致04000.1而不是它的总和应该显示4000.10。如何解决它
here in the below code EstbFee=0.00 and FutureEstbFee=4000.10 but when im trying to add these two it's resulting in "04000.1" rather it’s sum should display 4000.10 . How can solve it
txtEstablishmentFee.Text = (Convert.ToDouble(dt.Rows[0]["EstablishmentFee"]) + Convert.ToDouble(dt.Rows[0]["FutureEstablishmentFee"])).ToString().Trim();
提前致谢
Thanks in advance
推荐答案
txtEstbFee.Text = (Convert.ToDouble(dt.Rows[0]["EstbFee"]) + Convert.ToDouble(dt.Rows[0]["FutureEstbFee"])).ToString().Trim();
或者更好地分成几个步骤:
Or better break into several steps:
var estbFee = Convert.ToDouble(dt.Rows[0]["EstbFee"]);
var futureEstbFee = Convert.ToDouble(dt.Rows[0]["FutureEstbFee"]);
var totalFee = estbFee + futureEstbFee;
txtEstbFee.Text = totalFee.ToString();
这种方式很容易阅读。
This way it's easy to read.
txtEstbFee.Text = (Convert.ToDouble(dt.Rows[0]["EstbFee"]) + Convert.ToDouble(dt.Rows[0]["FutureEstbFee"])).ToString();
或者更好:
Or better:
txtEstbFee.Text = ((double)dt.Rows[0]["EstbFee"] + (double)dt.Rows[0]["FutureEstbFee"]).ToString();
假设您的列是数字的。如果它们不是,它们应该是!
Assuming your columns are numeric. If they aren't, they should be!
double value = Convert.ToDouble(dt.Rows[0]["EstbFee"]) + Convert.ToDouble(dt.Rows[0]["FutureEstbFee"]);
txtEstbFee.Text = value.ToString().Trim();
祝你好运!
ps。为什么列字符串而不是小数类型?然后不需要转换。
Good luck!
ps. why are the columns string instead of beeing a decimal type? Then no conversion is needed.
这篇关于价值在Zero之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!