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)
 Fixing Decimal Value without rounding

Author  Topic 

Aravind N R
Starting Member

6 Posts

Posted - 2013-12-26 : 07:11:12
Hi Team, How to Fix the decimal value with two values without rounding off

e.g if the value is 54.778 the output should be 54.77

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2013-12-26 : 07:26:04
ROUND(9, 2, {0 | 1} ).
See Books Online which parameter value {0 | 1} does truncating instead of rounding.



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

Aravind N R
Starting Member

6 Posts

Posted - 2013-12-26 : 07:39:40
Hi

You mean to say we can write like below


SELECT ROUND('54.778',<1 | 2>)
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2013-12-26 : 07:45:50
select ROUND(54.778, 2, 1)


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Aravind N R
Starting Member

6 Posts

Posted - 2013-12-26 : 07:56:40
Thanks, but here after decimal we will get three digit. It need to get fix with two digit

E.g The output for your query will be 54.770
but i need to get 54.77
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-12-26 : 11:10:15
quote:
Originally posted by Aravind N R

Thanks, but here after decimal we will get three digit. It need to get fix with two digit

E.g The output for your query will be 54.770
but i need to get 54.77


CAST it to decimal with scale value 2 then


SELECT CAST(ROUND(54.778, 2, 1) AS decimal(10,2))


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

Aravind N R
Starting Member

6 Posts

Posted - 2013-12-26 : 12:07:10
Thank You, It works and you rocks !!!

Thank You All for Replying.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-12-28 : 04:05:22
Welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -