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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to trim any numbers after tenth decimal

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2010-06-28 : 13:33:04
I am using teh following in SP:
Set @NewSequenceNO = @SequenceNO + 0.01

for example the sequence numbers appear this way: 6.01 or 6.02 etc

but sometime this is happening:
6.010004

how to remove any numbers after tenth decimal position to make it appear 6.01

Thank you very much for the helpful info.

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2010-06-28 : 13:40:20
That is probably a front end/dispaly issue. But, there are several ways to do this. Here ae a couple:
DECLARE @Foo DECIMAL(20,10)
SET @Foo = CAST('6.010004' AS DECIMAL(20,10))

SELECT @Foo, CAST(@Foo AS DECIMAL(20, 2)), ROUND(@Foo, 2)
Go to Top of Page

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2010-06-28 : 19:01:41
Are you using float or real as the data type for @NewSequenceNO or @SequenceNO? If so, these are "approximate" data types which might be why you are getting strange results in the first place.

=======================================
A couple of months in the laboratory can save a couple of hours in the library. -Frank H. Westheimer, chemistry professor (1912-2007)
Go to Top of Page
   

- Advertisement -