Home > Blockchain >  How to prevent automatically rounding the decimal part of the number in .NET 6
How to prevent automatically rounding the decimal part of the number in .NET 6

Time:05-15

After I converted the version from .NET Core 3.1 to 6.0, I figured out that all decimal(10, 5) type columns were automatically rounding the decimal part of the number and saved it in the database with the round format. Which in the previous version of .NET Core was working correctly. For example, I have a column like asset = 85.456, in the new version it is stored in the database with as a 85.46 value.

the upgrading version of the packages: EFCore version 2.13.4 => 6.13.18 EntityFrameworkCore.SqlServer version 2.2.6 => 6.0 and I'm using Microsoft SQL Server.

How can I prevent this?

CodePudding user response:

Can you be sure about your model builder like this in context class:

modelBuilder.Entity<TableName>(entity =>
{
    entity.Property(e => e.FieldName).HasColumnType("decimal(10, 5)");
});

If it is not for that, probably this field value type is not decimal(10,5) in your database.

  • Related