I'm adding float data in my sql table, but even though I'm adding the value 201.95, the table shows 201.949996... (a lot of decimal digits). Is there any way to handle this ?, since I only want two digits as decimal numbers.
Asked
Active
Viewed 711 times
1
-
what database system? what is the data type? – Daniel A. White Jun 10 '14 at 00:03
-
Microsoft SQL Server. I'm using with C# WinForms application. – Osman Esen Jun 10 '14 at 00:04
-
what's the data type of the column? – Daniel A. White Jun 10 '14 at 00:05
-
The datatype is float – Osman Esen Jun 10 '14 at 00:05
-
are you able to change that? float is an approximation. – Daniel A. White Jun 10 '14 at 00:06
-
Which data type do you suggest ?. I only have to use two decimal digits. – Osman Esen Jun 10 '14 at 00:08
-
I would use the `money` datatype – Simcha Khabinsky Jun 10 '14 at 00:08
-
`decimal` or `numeric`: http://msdn.microsoft.com/en-us/library/ms187746.aspx – Daniel A. White Jun 10 '14 at 00:08
-
Thank you very much Daniel. It was a basic data type problem. – Osman Esen Jun 10 '14 at 00:15
-
are you sure you're adding 201.95? you just type it in a text field and the n save it to a database? what's the value of the variable prior to be sent to SQL when you debug? – Matimont Jun 10 '14 at 00:15
2 Answers
2
You may have to re-create the table with the column using DECIMAL(x, 2)
as data-type.
Where x is any value defined in below article.
0
Good to use Decimal or numeric(18,2) (18 is total length and 2 for decimal value) check this
declare @temp float = '201.9500011'
select @temp
declare @temp1 numeric(18,2) = '201.9500011'
select @temp1