gpt4 book ai didi

asp.net - asp.net中字符串变量中整数值的减法

转载 作者:行者123 更新时间:2023-12-02 15:32:28 25 4
gpt4 key购买 nike

我正在使用 ASP.NET 开发一个网站,遇到以下问题:

 string price = row["Price"].ToString();
string discount = row["Discount"].ToString();

此代码用于从 DataTable 获取数据,并且工作正常。两者都是浮点值(12,50.75...)。在我的程序中,我想从“价格”中减去“折扣”并将结果分配给一个新字符串。假设字符串价格包含 50 且字符串折扣包含 23.5,那么我希望新字符串中包含 26.5。我该如何实现这个目标?

最佳答案

您可以使用以下代码:

    string strPrice =  row["Price"].ToString();
string strDiscount =row["Discount"].ToString();
string strFinal = (Convert.ToDouble(strPrice) - Convert.ToDouble(strDiscount)).ToString();

关于asp.net - asp.net中字符串变量中整数值的减法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14110125/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com