March 19, 2003 at 1:34 pm
I am inserting a value in float like 20.89 and it is inserting like 20.899999999999999
I just want it to store exact value like 20.89.
March 19, 2003 at 2:15 pm
What is your exact table CREATE statement and exact INSERT statement?
March 19, 2003 at 2:31 pm
sorry procedure name is without @
March 19, 2003 at 3:15 pm
Then you should not use float, use something like decimal(9,2) instead.
--
Chris Hedgate @ Apptus Technologies (http://www.apptus.se)
March 19, 2003 at 3:15 pm
Is TestField1 column of type float? What if you output @val1 rught before the INSERT statement? What does it print?
You forgot to show me the CREATE TABLE statement.
I actualy would not be surprised to see 20.8899999999 but 20.89999999 does not make sense.
March 19, 2003 at 3:46 pm
create procedure test1
@val1 float,
@val2 int
as
declare @val3 decimal(9,2)
select @val3 = @val1
insert into testtable1
(TestField1, testfield2)
values
(@val3, @val2)
-----------------------
exec test1 20.8,12
I did it and it is still storing it
20.800000000000001
March 19, 2003 at 3:48 pm
Before insert also it is like this
20.800000000000001.
I don't want to change it to decimal. Is there no way to fix it to 2 decimals only
March 20, 2003 at 1:07 am
Why do you not want to change it? The float data type is for storing approximations and uses scientific notation to store the values. You will never be able to store it with two decimals. If you want to you can convert it to decimal when retrieving it if you're only after showing it in with two decimals.
--
Chris Hedgate @ Apptus Technologies (http://www.apptus.se)
March 20, 2003 at 1:06 pm
Sometimes we start thinking impossible.
Anyway Thanks!!
March 21, 2003 at 11:41 am
quote:
create procedure test1@val1 float,
@val2 int
as
declare @val3 decimal(9,2)
select @val3 = @val1
insert into testtable1
(TestField1, testfield2)
values
(@val3, @val2)
-----------------------
exec test1 20.8,12
I did it and it is still storing it
20.800000000000001
If your data column is still defined to be of type float you are going to get appreciable round-off error. Chris Hedgate was quite accurate is stating that float and real (ironically) don't store the real value but rather an approximation. Converting your float parameter (@Val1) to decimal(9, 2) but then storing it in a float data column cannot preserve accuracy.
If you want accuracy, you cannot use an approximation.
Remember, also, that the database is responsible for the data proper. How that data gets formatted on the page or report is a function of the application.
HTH
Steve Hendricks
MCSD, MCDBA
AFS Consulting Group
(949) 588-9800 x15
Steve Hendricks
MCSD, MCDBA
Data Matrix
shendricks@afsconsulting.com
(949) 588-9800 x15
March 24, 2003 at 7:12 am
My bad. I was using DBArtisan which, for some reason, only displayed 20.8. I tried it in QueryAnalyzer and got 20.800000000000001.
?
March 24, 2003 at 7:22 am
Ah, phew. I was getting a bit confounded there for a while.
--
Chris Hedgate @ Apptus Technologies (http://www.apptus.se)
Viewing 14 posts - 1 through 13 (of 13 total)
You must be logged in to reply to this topic. Login to reply