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.
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.701declare @dp tinyint = 2set @NewNum = ROUND(@NewNum, @dp) print @NewnumShould return 0.70 if @dp is 2 decimal places.or if you pass the number 0 it should return 0.00How 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.) |
|
|
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 |
|
|
SergioM
Posting Yak Master
170 Posts |
Posted - 2012-10-12 : 14:09:49
|
Hmm, it works for me. Try it.DECLARE @NewNum float = 0.701PRINT CAST(@NewNum AS DECIMAL(19,2)); -SergioI use Microsoft SQL 2008 |
|
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2012-10-13 : 16:48:41
|
Thanks |
|
|
|
|
|