如何在显示之前将所有 "Integer-like" 值转换为附加“.0”?

How can I transform all "Integer-like" values to append ".0" prior to being displayed?

我在 Decimal(2,1) SQL 服务器字段中有值的记录,例如 7.0、8.0 和 9.0,当在我的 GridView 中显示时,它们显示为“7”、“8” ", 或 "9"

我希望它们显示为“7.0”、“8.0”和“9.0”,这样它们看起来就像是 8.3、7.4、9.1 等的“兄弟”

如何让我的 WebForms 站点上的 GridView 显示它们的完整值(带小数点和 0),即使(例如)8 与 8.0 相同?

更新

这是我获取数据并将其分配给 GridView 的地方:

private void GetFilteredData(string completeQuery)
{
    string connStr = ConfigurationManager.ConnectionStrings 
                ["Gr8GooglyMooglyConnectionString"].ToString();
    try
    {
        using (SqlConnection connection = new SqlConnection(connStr))
        {
            using (SqlCommand cmd = new SqlCommand(completeQuery, 
                                                   connection))
            {
                cmd.Parameters.Add(new SqlParameter("@IMDBMinRating", 
                    SqlDbType.Decimal) { Precision = 2, Scale = 1, Value = 
                    _imdbThreshold });
                cmd.Parameters.Add("@EarliestYear", SqlDbType.Char, 4).Value 
                    = _yearBegin;
                cmd.Parameters.Add("@LatestYear", SqlDbType.Char, 4).Value = 
                    _yearEnd;
                
                SqlDataAdapter dAdapter = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                dAdapter.Fill(ds);
                GridView1.DataSource = ds;
                GridView1.DataBind();
            }
        }  
    }
    catch (Exception ex)
    {
        string s = ex.Message;
        s = s + "Oopsa-daisy!";
    }
}

更新 2

.aspx 网格

<div style="width: 100%; height: 500px; overflow: scroll">
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"          
            OnDataBound="GridView1_DataBound" OnPreRender="GridView1_PreRender"              
            OnSelectedIndexChanged="GridView1_SelectedIndexChanged"          
            AutoGenerateSelectButton="True">
        <Columns>
            <asp:BoundField DataField="MovieId" HeaderText="Movie Id" ItemStyle- 
                Width="0%" SortExpression="MovieId" />
            <asp:BoundField DataField="MovieTitle" HeaderText="MovieTitle"       
                SortExpression="MovieTitle" />
            <asp:BoundField DataField="IMDBRating" HeaderText="IMDBRating"       
                SortExpression="IMDBRating" />
            <asp:BoundField DataField="MPAARating" HeaderText="MPAARating"       
                SortExpression="MPAARating" />
            <asp:BoundField DataField="YearReleased" HeaderText="YearReleased"       
                SortExpression="YearReleased" />
            <asp:BoundField DataField="Minutes" HeaderText="Minutes" 
                SortExpression="Minutes" />
        </Columns>
    </asp:GridView>
</div>

   

您可以在 BoundField 上使用 DataFormatString 属性 来指定呈现数据的格式。例如,要在数字后显示数字,您可以使用 F1,类似于:

<asp:BoundField DataField="IMDBRating" HeaderText="IMDBRating"       
                SortExpression="IMDBRating" DataFormatString="{0:F1}" />