- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试更新从数据库中检索到的 DataTable,然后再将其绑定(bind)到 Gridview。
但是,当我更新小数字段时,小数点后的部分被归零。我错过了什么?
if (HttpContext.Current.Request.IsAuthenticated)
{
// Get additional price matches
using (SqlConnection stockConn = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString))
{
// Check for trade match offer
SqlCommand tradePCCheck = new SqlCommand("getAllMyPriceMatches", stockConn);
tradePCCheck.CommandType = CommandType.StoredProcedure;
SqlParameter email = tradePCCheck.Parameters.Add("@email", SqlDbType.NVarChar);
try
{
email.Value = this.Context.User.Identity.Name;
}
catch
{
email.Value = " ";
}
SqlParameter thedate = tradePCCheck.Parameters.Add("@theDate", SqlDbType.DateTime);
thedate.Value = DateTime.Now.AddHours(-50);
stockConn.Open();
SqlDataReader pcReader = tradePCCheck.ExecuteReader();
pms.Load(pcReader);
pcReader.Close();
stockConn.Close();
}
}
//Set Connection, Open the DB & Fill Data Set
using (SqlConnection stockConn = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString))
{
SqlCommand stockCommand = new SqlCommand("getTISearchResults", stockConn);
stockCommand.CommandType = CommandType.StoredProcedure;
SqlParameter keyword = stockCommand.Parameters.Add("@keyword", SqlDbType.NVarChar);
keyword.Value = prefixText;
stockConn.Open();
SqlDataReader rd = stockCommand.ExecuteReader();
searchResults.Load(rd);
stockCommand.Dispose();
rd.Dispose();
}
// Update Results with elevated prices...
foreach (DataRow dr in searchResults.Rows)
{
// Check for PMS
DataRow[] thePMS = pms.Select("tpc_stockid = '" + dr["stockitem_number"].ToString() + "'");
if (thePMS.Length > 0)
{
decimal px = 0;
decimal cash = 0;
if (thePMS[0]["tpc_pricepx"] != null && !thePMS[0]["tpc_pricepx"].ToString().Equals(""))
{
px = Convert.ToDecimal(thePMS[0]["tpc_pricepx"]);
}
if (thePMS[0]["tpc_price"] != null && !thePMS[0]["tpc_price"].ToString().Equals(""))
{
cash = Convert.ToDecimal(thePMS[0]["tpc_price"]);
}
// update table and accept changes
DataRow[] theRows = searchResults.Select("stockitem_number = '" + dr["stockitem_number"].ToString() + "' ");
if (theRows.Length > 0)
{
theRows[0]["stockitem_pxprice"] = px;
theRows[0]["stockitem_cashprice"] = cash;
searchResults.AcceptChanges();
}
}
}
gvSearchResults.DataSource = searchResults;
gvSearchResults.DataBind();
我在赋值之前输出了 PX 和 Cash,它们保存了正确的值 800.19 和 500.12,但是在 AcceptChanges 之后并且一旦它们被绑定(bind),输出就是 800.00 和 500.12。
theRows[0]["stockitem_pxprice"]
和 theRows[0]["stockitem_cashprice"]
都是 decimal(5,2)
在填充 searchResultsDT 的数据库上。
非常感谢任何帮助。
谢谢。
最佳答案
是的,您在将值设置到网格中时缺少 string.format
。在设置之前,您需要先格式化 double。
比如说,如果你得到一个像 4.506 这样的数字,它会显示类似 4.5060 的东西,或者如果你有一个像 4.5 这样的数字,那么它会显示为 4.50。
我在模板化的 gridview 中遇到过这个问题,不得不使用 string.format 和格式说明符来解决它。
关于c# - DataRow 在更新 Datatable 时将小数点的小数部分归零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13952812/
如何将整数类型转换为 double /浮点类型以显示小数点?例如,如果我想将数字转换为货币格式: 5 会变成 5.004.3 会变成 4.30 javascript 有什么东西可以用来做这种转换吗?
【版权声明】未经博主同意,谢绝转载!(请尊重原创,博主保留追究权) https://www.cnblogs.com/cnb-yuchen/p/18107586 出自【进步*于辰的博客】
我意识到这是一个重复的问题,但是 this 中提到的解决方案这个问题完全不适合我。 我目前的代码如下 Sub ConvertTextToNumber() Dim Area As Range, C As
我正在使用数学 javascript,但在用它来替换点的逗号和逗号的点时遇到了一些麻烦。我可以改变千位分隔符的逗号,但无法设法将小数点变成逗号。我尝试了其他帖子中的一些建议,但没有感到高兴。目标是实现
我正在尝试在 Android 中创建一个数字选择器,但轮子只增加 1。我想增加 0.1。我在网上查了一下,但我发现了一个格式化的浮点数组禁用了轮子。请帮助并为语法感到抱歉,我正在学习。 最佳答案 您可
我正在尝试在多个网站上获取利率。数据相当非结构化,但形式足够接近。我想要捕捉的内容: x.xx% 至 xx.xx% 数据示例: 由 FDIC 成员 WebBank 发放的所有贷款。您的实际利率取决于信
在 MySQL 表中,我有一个具有不同值的 VARCHAR 列,这些值可能代表字符串、整数、浮点、任意值。这些值作为特定于语言的字符串写入数据库,这意味着 123.45 的浮点值可以写为德语中的 "1
我想编写一个正则表达式,它允许整数或具有 0 - 2 个小数位的小数。 有效输入 1 1. 1.1 1.11 111111111 111111111. 111111111.1 111111111.11
我正在尝试为 nullable 实现客户端验证其小数点分隔符可以是逗号(例如:123,45)。 在我看来: ... @Html.LabelFor(model => model.Turnove
我找不到合适的正则表达式来仅从字符串中提取 float 。考虑以下字符串: $string = "8x2.1 3x2"; 我想提取 2.1,我尝试了以下操作,但这给了我整数和 float : preg
我希望使用正则表达式函数分离以下数据,如下所示: 要使用的功能: let fx=(text,regex)=> Web.Page( " var x='
我是 jquery 新手。我有一个带有两个输入框的表单。我实现了一些验证。 Min.Amount Max.Amount
我正在java中实现一个简单的算法,它接受一个整数数组,并查找并返回数组中相邻整数的最大乘积。 为此,我首先初始化了一个名为largestProduct的变量,我用它来跟踪当前找到的最大(最佳)产品。
在 JavaScript 中,我想定义小数点的位置。我只能在示例中真正展示它。 假设输入值为 1234 。 我希望输出为 123.4 。 或者,如果输入是 12345 ,我希望输出是 123.45 。
我有这段代码,只允许在 keypress() 的输入字段中输入数字 if (e.which != 8 && e.which != 0 && (e.which 57)) { return fa
我目前正在开发一些基于 Django 的 Web 项目,在这个 Web 开发过程中,我遇到了以下我无法正确理解的代码。 if price_product['price'] == Decimal('-1
这个问题在这里已经有了答案: How do I print a double value with full precision using cout? (17 个答案) 关闭 7 年前。 我试图在
这应该是微不足道的,但我正在兜圈子,也许有人可以提供帮助。 我有两个表(T1,T2),我希望从中提取每行中的多个值并更新第三个表(T3)的内容当且仅当)T1 中有两个 UQ,NN 字段,T2 匹配,在
如果数字不是十进制,我需要附加.00,但是当我尝试下面的代码时,它会将整个数字更改为0.00。例如,如果数字是12,200,它会将其更改为0.00,而不是在末尾添加.00 $('.total-amou
我正在尝试在容器 View 中设置 9:16 纵横比 View 。以下代码在 viewDidLayoutSubviews 中设置约束,以便在正确的位置考虑自动布局。它还调用 layoutIfNeede
我是一名优秀的程序员,十分优秀!