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

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

Starting Member

9 Posts

Posted - 01/24/2013 :  11:13:35  Show Profile  Reply with Quote

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?


James K
Flowing Fount of Yak Knowledge

3865 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

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 01/25/2013 :  00:56:39  Show Profile  Reply with Quote
also see


SQL Server MVP

Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.05 seconds. Powered By: Snitz Forums 2000