Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to avoid number truncation

Author  Topic 

sxbo672158
Starting Member

4 Posts

Posted - 2011-04-28 : 15:38:34
My original SQL table has two variables with values like this:
41.765433, -122.8943333.
But when I write a query (SELECT * FROM table, with a few conditions)and output my result into a new txt file,those numbers are truncated with only 3 decimal places(41.765,-122.894)
Is there any way to avoid this? (The new value cause huge errors)

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2011-04-28 : 15:55:04
ensure that the data type holds that precision...

I think decimal(11,7) should hold it...

Corey

I Has Returned!!
Go to Top of Page

sxbo672158
Starting Member

4 Posts

Posted - 2011-04-28 : 16:21:24
original data type is float(20), does that mean I only need to change float(20) into decimal(11,7)?
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2011-04-28 : 16:44:13
Well a float(20) is the same as a real, which is: - 3.40E + 38 to -1.18E - 38, 0 and 1.18E - 38 to 3.40E + 38

So I'd guess if you want to get as close as possible with a numeric/decimal you'd want to use the full 38 digits of precision.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-04-29 : 00:46:01
quote:
But when I write a query (SELECT * FROM table, with a few conditions)and output my result into a new txt file,those numbers are truncated with only 3 decimal

how do you output the result into text file ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2011-04-29 : 04:55:17
DECLARE @FirstFloat FLOAT, @SecondFloat FLOAT
SELECT @FirstFloat= 421.765433, @SecondFloat = -122.8943333
SELECT CONVERT(VARCHAR(50),@FirstFloat,128),CONVERT(VARCHAR(50),@SecondFloat,128)
--------------------------
http://connectsql.blogspot.com/
Go to Top of Page
   

- Advertisement -