Can’t store decimal value in SQL. Want to store like decimal(2,8)
Like 32.12345678
[Column(TypeName = "decimal(2,8)")] [Display(Name = "Latitude")] public decimal Latitude { get; set; }
In NuGet Consol
Failed executing DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] CREATE TABLE [DredgingDatas] ( [Id] int NOT NULL IDENTITY, [DredgerId] int NOT NULL, [DredgingTime] datetime2 NOT NULL, [Density] decimal NOT NULL, [Velocity] decimal NOT NULL, [Production] decimal NOT NULL, [Latitude] decimal(2, 8) NOT NULL, [Longitude] decimal(2, 8) NOT NULL, [Tide] decimal NOT NULL, [DredgeHead] float NOT NULL, CONSTRAINT [PK_DredgingDatas] PRIMARY KEY ([Id]), CONSTRAINT [FK_DredgingDatas_Dredgers_DredgerId] FOREIGN KEY ([DredgerId]) REFERENCES [Dredgers] ([DredgerId]) ON DELETE CASCADE ); The scale (8) for column 'Latitude' must be within the range 0 to 2.
Advertisement
Answer
Your issue is a slight misunderstanding of the decimal data type. The first part of the declaration is the total length of the data field, the second is the amount of those that are decimals.
For example: decimal(5,3)
shows a precision of 5 total digits, 3 of those are decimal places (12.345).
I think you are looking for the data type decimal(10,8)
which would give you 10 total digits, with 8 of those coming after the decimal place
Here’s a link to the documentation that explains how the precision works;