I'm loading data from a MySQL database into a C# .NET application. The data is held in the database as DBType.Double, but for use in my application I cast to Decimal using Convert.ToDecimal(). The data is positional data used in surveying and can be used to display a 3D model in a Direct3D window.
When the Direct3D window, and hence the Direct3D dll is not loaded, the conversion works fine, so that values like 1769301.6485186936, 5880300.8152837148 held in the database are loaded as 1769301.64851869, 5880300.81528371. However, if I have loaded the Direct3D module then the conversion results in the same values converting to 1769301.7112576, 5880300.79401984.
The basic code is as below, where vertex is a class/struct of 3 decimal values, X,Y and Z.
List<vertex> positions = new List<vertex>();
using (MySqlCommand cmd = new MySqlCommand("SELECT x, y, z FROM positionTable;", conn))
{
MySqlDataReader dr = cmd.ExecuteReader();
try
{
while (dr.Read())
{
vertex position = new vertex();
position.X = Convert.ToDecimal(dr[0]);
position.Y = Convert.ToDecimal(dr[1]);
position.Z = Convert.ToDecimal(dr[2]);
positions.Add(position);
}
}
}
NumberFormatInfo
for the thread in question. See NumberFormatInfo for information on setting it. – Jointress