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 2008 Forums
 Transact-SQL (2008)
 Round Function in TSQL

Author  Topic 

faijurrahuman
Starting Member

15 Posts

Posted - 2012-02-28 : 06:47:17
Hi ;

I want to round the last two numbers , below my query

DECLARE @N float

set @N=(SELECT CONVERT(numeric,(493-1)) / 493 *100)

PRINT @N

Result

99.7971

Expected Result

99.80

DECLARE @a Float

SET @a=(select CONVERT(numeric,(24625- 1 ))/24625 *100)

PRINT @a

Result

99.9959

Expected Result

99.99

In this two cases are solve the problems.

any one help this problems


Share Knowledge team

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2012-02-28 : 07:00:57
Have you tried the ROUND() function?

You second result should round up as it is over halfway towards the next whole number, is there any reason to round down?
Go to Top of Page

faijurrahuman
Starting Member

15 Posts

Posted - 2012-02-28 : 07:11:34
yes ...

Share Knowledge team
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-02-28 : 07:25:17
You can use round function, but there are some caveats you need to be aware of, discussed in this thread: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=158176

For your example:
DECLARE @N float

set @N=(SELECT CONVERT(numeric,(493-1)) / 493 *100)

PRINT ROUND(@N,2)

DECLARE @a Float

SET @a=(select CONVERT(numeric,(24625- 1 ))/24625 *100)

PRINT ROUND(@a,2,1)

Go to Top of Page
   

- Advertisement -