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
 Truncating the last few digits of a float

Author  Topic 

sqlservernovice
Starting Member

9 Posts

Posted - 2013-01-24 : 11:13:35
Hi,


i have values like this -1.45000001339213E-06 in the column defined as float. I want to be able to exclude or truncate the E-06 part of the value. when i try cast it give me the error 'Arithmetic overflow error converting float to data type numeric'. Round also does not work.

How can i do it?

Thanks

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-01-24 : 11:38:59
How are you trying to truncate it? "Truncate" may be a misnomer - you can express the same number in other formats. For example see the code below. Also, float is an approximate representation, so the result you get back may not be exactly the same
create table #tmp(floatval float);
insert into #tmp values ('-1.45000001339213E-06');
select cast(floatval as decimal(19,16)) from #tmp
drop table #tmp;
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-01-25 : 00:56:39
also see

http://visakhm.blogspot.in/2012/08/floating-point-formats-in-sql-server.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -