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 |
|
kwikwisi
Constraint Violating Yak Guru
283 Posts |
Posted - 2009-01-03 : 11:00:28
|
| Hellohow can i retrieve int field as 2 decimal places like (1985 should be 19.85)thanks in advance |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2009-01-03 : 12:10:51
|
| DECLARE @SomeInt INTSET @SomeInt = 1985SELECT CAST(@SomeInt/100.0 AS DECIMAL(10,2))The specified decimal place on the 100 is necessary, otherwise you'll get integer division and a result of 19.00--Gail ShawSQL Server MVP |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-03 : 13:55:55
|
quote: Originally posted by GilaMonster DECLARE @SomeInt INTSET @SomeInt = 1985SELECT CAST(@SomeInt/100.0 AS DECIMAL(10,2))The specified decimal place on the 100 is necessary, otherwise you'll get integer division and a result of 19.00--Gail ShawSQL Server MVP
whats the purpose of final CAST? wont @SomeInt/100.0 be enough? |
 |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2009-01-03 : 15:23:00
|
quote: Originally posted by visakh16 whats the purpose of final CAST? wont @SomeInt/100.0 be enough?
To get the final display to have only 2 decimals. Without it, it returns 19.850000It could be left out if the result is not going to be displayed directly.--Gail ShawSQL Server MVP |
 |
|
|
thiyagu_rind
Starting Member
46 Posts |
Posted - 2009-01-23 : 00:33:30
|
| Yes, we have to use the CAST at last step. By the below casting also you can achieve this.DECLARE @SomeInt INTSET @SomeInt = 1985SELECT CAST(@SomeInt/100.0 AS FLOAT)RegardsThiyagarajanwww.sqlhunt.blogspot.com |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-23 : 00:53:15
|
quote: Originally posted by thiyagu_rind Yes, we have to use the CAST at last step. By the below casting also you can achieve this.DECLARE @SomeInt INTSET @SomeInt = 1985SELECT CAST(@SomeInt/100.0 AS FLOAT)RegardsThiyagarajanwww.sqlhunt.blogspot.com
better to use decimal or numeric rather than float as it gives only an approximate value |
 |
|
|
|
|
|