user6279040
user6279040

Reputation:

SQL Table Data insertion

I am trying to enter data into my table, the column is of type decimal. When I enter 13.99, it automatically rounds up to 14. How do I stop it from doing so?

CREATE TABLE [dbo].[products] 
(
    [productsID] INT IDENTITY (1, 1) NOT NULL,
    [name] VARCHAR(50) NOT NULL,
    [price] DECIMAL(18) NOT NULL,
    [image] VARCHAR(255) NOT NULL,

    PRIMARY KEY CLUSTERED ([productsID] ASC)
);

Upvotes: 0

Views: 40

Answers (2)

user1935361
user1935361

Reputation: 442

Your data type is Decimal(18). According to the documentation, you need to specify the number of decimal places you need; e.g. Decimal(18, 2) for two decimal places.

The docs state that the second parameter (s or scale) is:

The number of decimal digits that will be stored to the right of the decimal point...The default scale is 0;

Since you didn't have 'room' for the decimal places, they were taken off.

Upvotes: 1

Yanely Ramirez
Yanely Ramirez

Reputation: 11

Decimal takes in two values, view their documentation to make sure you are passing in the right values to get the outcome you want.

Upvotes: 1

Related Questions