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 2000 Forums
 Transact-SQL (2000)
 Truncating

Author  Topic 

reflex2dotnet
Yak Posting Veteran

99 Posts

Posted - 2007-05-17 : 13:58:02
Hi all

I am calculating a value as
@test=(@stock/@AVERAGE)
in my SP

The reulst i am getting for
select @test as Price is like 56.9877655544
But how can i truncate so that i will get 56.98

Please help me to fix this
Thanks

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2007-05-17 : 14:05:40
Use the CONVERT function to convert the result to decimal(4,2).
Or better yet, let your interface handle the formatting, because that is where such conversions are supposed to happen.

e4 d5 xd5 Nf6
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-05-17 : 14:06:52
use decimal(X,2), wherre 2 is the precision.
Declare @x decimal(15,8)
set @x =56.9877655544
select convert(decimal(10,2), @x)


Dinakar Nethi
SQL Server MVP
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

reflex2dotnet
Yak Posting Veteran

99 Posts

Posted - 2007-05-17 : 15:13:19
Thanks to all
I will try your idea

Thank you
Go to Top of Page
   

- Advertisement -