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 2008 Forums
 Transact-SQL (2008)
 round
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

arkiboys
Flowing Fount of Yak Knowledge

1406 Posts

Posted - 08/20/2012 :  09:49:02  Show Profile  Reply with Quote
Hi,
I am rounding numbers to 2 decimal places.
How is it possible to get the 0 at the end also?
For example, rounding 8.1243 gives 8.12
But rounding 6.4 gives 6.4 whereas I would like to see 6.40
OR if the answer is say 2 I would like to see 2.00
How is this done please?
Thanks

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 08/20/2012 :  10:05:04  Show Profile  Reply with Quote
Use DECIMAL. That would round it as well by default.
DECLARE @x FLOAT = 2.0;

SELECT ROUND (@x,2);
SELECT CAST(@x AS DECIMAL(19,2))
Go to Top of Page

arkiboys
Flowing Fount of Yak Knowledge

1406 Posts

Posted - 08/20/2012 :  13:26:28  Show Profile  Reply with Quote
Thanks
Go to Top of Page

Lamprey
Flowing Fount of Yak Knowledge

4613 Posts

Posted - 08/20/2012 :  13:53:40  Show Profile  Reply with Quote
Just to add to what Sunitbeck said, if you pass in a numeric/decimal, you'll get that same datatype back out.
DECLARE @x FLOAT = 2.0;
SELECT ROUND (CAST(@x AS DECIMAL(19, 2)), 2);

DECLARE @y DECIMAL(19, 2) = 2.0;
SELECT ROUND (@y, 2);
But, then there isn't really a need to round, assuming the datatype has the precision you want:
DECLARE @z DECIMAL(19, 2) = 2.12345;
SELECT @z

Edited by - Lamprey on 08/20/2012 13:56:48
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