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 - show leading zero

Author  Topic 

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2012-10-11 : 07:24:04
I would like to get the leading zero in the below sql.

declare @NewNum float = 0.701
declare @dp tinyint = 2
set @NewNum = ROUND(@NewNum, @dp)
print @Newnum

Should return 0.70 if @dp is 2 decimal places.
or if you pass the number 0 it should return 0.00

How is this done please?
Thanks

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-10-11 : 07:42:41
[code]CAST(@NewNum AS DECIMAL(19,2));[/code]If you have very precise/stringent formatting requirements, usually that is better done at the presentation side (such as a client GUI, reporting services etc.)
Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2012-10-11 : 07:50:34
Hi,
This does not seem to work in my sql.
I tried what you mentioned but still gives 0.7 and NOT 0.70
Go to Top of Page

SergioM
Posting Yak Master

170 Posts

Posted - 2012-10-12 : 14:09:49
Hmm, it works for me. Try it.
DECLARE @NewNum float = 0.701
PRINT CAST(@NewNum AS DECIMAL(19,2));


-Sergio
I use Microsoft SQL 2008
Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2012-10-13 : 16:48:41
Thanks
Go to Top of Page
   

- Advertisement -