1
There’s some time I’ve been noticing, something strange when saving values double
in the SQL Server database with the Entity Framework.
I noticed that when reporting a value ex: 12.23 after recording the information is breaking the decimals in more houses ex: 12.22501.
This does not occur frequently and not every time a value is recorded, and also has no impact on calculations (as I do not use round
).
My doubts are:
- Why does this happen?
- Has anyone been there? How did you solve?
- It is configuration or depends on the type of database?
The structure I use is informed below:
public class MyClass
{
public double MyClass { get; set; };
}
public class MyContext : DbContext
{
public DbSet<MyClass> MyClass;
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<MyClass>().Property(x => x.ValorTeste).HasPrecision(16, 5);
}
}