Reputation: 133
I am using Microsoft SQL Server Management Studio and C# to insert some rows into this database. The first column of this table is a code (type varchar(20)
) and the second one is a float
. The problem arises because if I want to enter 3,71, the database stores 3,7100000381469727.
Code:
float superficieL = float.Parse(row.Cells[indexSuperficie].Value.ToString(), new CultureInfo("es-ES"));
The value inserted in the database as a float is this variable, and I get his value from a datagridview that only contains 3,71.
More examples:
Why is this happening?
Upvotes: 0
Views: 62
Reputation: 5634
Please refer this article for understanding how float, double and decimal data type works in .NET
Also, please refer this article which suggests what are options available to store decimals in a SQL Server database.
You can either use real, float or decimal type for your case.
In your case, I would suggest to use the Decimal
datatype in a SQL Server table, as it provides better precision and I believe that's what you asked for.
Hope this helps.
Upvotes: 3