I have a webpage that gets the data from the db and than displays it online but for some reason if the value is 0.4
it's changing it to 0.400000005960464
and if it's 859.8
it changes it to 859.799987792969
. I debugged it and saw that it's reading values correctly from the db so that's not the issue but it's the .aspx
page that is messing up the values. This is what I have for that page, it's DataField Component 1 and 2 that are getting changed.
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="TestData.aspx.cs"
Inherits="Inventory_TestData" Title="Module Test Data" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<ul>
<li>Item ID:
<asp:TextBox ID="txtItem" runat="server" AutoPostBack="True" OnTextChanged="txtItem_TextChanged"></asp:TextBox></li></ul>
<li style="text-align: left"><span style="color: #009999">Test Data:</span><asp:ObjectDataSource
ID="dsrcGetTestData" runat="server" SelectMethod="getTestData" TypeName="TestDataReader" DeleteMethod="deleteData">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="0" Name="nItemID" QueryStringField="Item" Type="Int32" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter DefaultValue="" Name="TestID" Type="Int32" />
<asp:Parameter DefaultValue="0" Name="TestType" Type="Object" />
</DeleteParameters>
</asp:ObjectDataSource>
<asp:GridView ID="gvTestItem" runat="server" AutoGenerateColumns="False" BackColor="White"
BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4"
DataSourceID="dsrcGetTestData" Font-Size="0.65em" ForeColor="Black" GridLines="Vertical" DataKeyNames="TestID">
<FooterStyle BackColor="#CCCC99" />
<Columns>
<asp:CommandField ShowDeleteButton="True" />
<asp:BoundField DataField="Component1" HeaderText="Component1" SortExpression="Component1" />
<asp:BoundField DataField="Component2" HeaderText="Component2" SortExpression="Component2"/>
</Columns>
<RowStyle BackColor="#F7F7DE" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</asp:Content>
You can try adding format string to your columns. For example following
<asp:BoundField DataFormatString="{0:F3}" DataField="Component1" HeaderText="Component1" SortExpression="Component1" />
<asp:BoundField DataFormatString="{0:F3}" DataField="Component2" HeaderText="Component2" SortExpression="Component2"/>
will limit number to 3 decimal points.