Ali Nouman
Ali Nouman

Reputation: 3412

SQL Server 2005 is changing decimal to integer

My column's datatype is decimal(18,0) but when I am entering value in to database 2.3 it changes into 2.

Upvotes: 0

Views: 913

Answers (2)

Oleg Dok
Oleg Dok

Reputation: 21776

For storing this value field should have a type of decimal(18,1)

Check it:

SELECT CAST(2.3 as decimal(18,0))
SELECT CAST(2.3 as decimal(18,1))

Upvotes: 3

Rob
Rob

Reputation: 45789

decimal(18, 0) means that you want to create a decimal field which stores:

  • 18 digits, shared between the left and right sides of the decimal place.
  • 0 digits to the right of the decimal place.

That explains why 2.3 is being turned into 2. For further detail, see the msdn documentation for the decimal datatype.

Upvotes: 3

Related Questions