BAD_SEED
BAD_SEED

Reputation: 5056

Why in SQL Server Decimal type round up every decimal result?

I have this TSQL script:

declare @dcml decimal
declare @flt float

SELECT @dcml = 5/cast(4 AS float)
PRINT(@dcml) -- return 1

SELECT @flt = 5/cast(4 AS float)
PRINT(@flt)  -- return 1.25

Why in the first case the result is rounded even with a decimal container for result?

Upvotes: 2

Views: 136

Answers (1)

Lasse V. Karlsen
Lasse V. Karlsen

Reputation: 391316

Because by default, the number of digits that are stored after the decimal point is 0, and you haven't specified a value to override this.

See the MSDN documentation here.

To fix:

declare @dcml decimal(18,5)

This will store 5 digits after the decimal point.

Basically you had an integer type there.

Upvotes: 2

Related Questions