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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Truncating the last few digits of a float
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sqlservernovice
Starting Member

9 Posts

Posted - 01/24/2013 :  11:13:35  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 01/24/2013 :  11:38:59  Show Profile  Reply with Quote
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

India
52326 Posts

Posted - 01/25/2013 :  00:56:39  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.16 seconds. Powered By: Snitz Forums 2000