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

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Fixing Decimal Value without rounding
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Aravind N R
Starting Member

India
6 Posts

Posted - 12/26/2013 :  07:11:12  Show Profile  Reply with Quote
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

Sweden
30217 Posts

Posted - 12/26/2013 :  07:26:04  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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

India
6 Posts

Posted - 12/26/2013 :  07:39:40  Show Profile  Reply with Quote
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)

Singapore
17601 Posts

Posted - 12/26/2013 :  07:45:50  Show Profile  Reply with Quote
select ROUND(54.778, 2, 1)


KH
Time is always against us

Go to Top of Page

Aravind N R
Starting Member

India
6 Posts

Posted - 12/26/2013 :  07:56:40  Show Profile  Reply with Quote
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

India
52317 Posts

Posted - 12/26/2013 :  11:10:15  Show Profile  Reply with Quote
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

India
6 Posts

Posted - 12/26/2013 :  12:07:10  Show Profile  Reply with Quote
Thank You, It works and you rocks !!!

Thank You All for Replying.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 12/28/2013 :  04:05:22  Show Profile  Reply with Quote
Welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
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.06 seconds. Powered By: Snitz Forums 2000