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 |
sqlslick
Yak Posting Veteran
83 Posts |
Posted - 2014-02-10 : 13:55:08
|
Hey guys,This is probably a dumb question but 3133232 / 1048576 = 2.9880828857421875. If you execute SELECT 3133232 / 1048576 the result is 2. How can I get it to display 2.98? I've tried the code below but that generates 2.00.SELECT CAST(3133232 / 1048576 AS DECIMAL (10, 2))Thanks in advanced! |
|
sqlslick
Yak Posting Veteran
83 Posts |
Posted - 2014-02-10 : 14:08:46
|
Nevermind, SELECT 3133232 / 1048576.0 did the trick. Just have to use the ROUND() function now for precision. |
 |
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2014-02-10 : 14:19:07
|
yeah, when performing division in sql server the scale and precision of the denominator determines the scale and precision of the result. Then if you want to round the result that is a separate operation. Your first statement resulted in an integer because that is what your denominator was. and casting an int to decimal(10,2) just results in zeros to the right of the decimal.Be One with the OptimizerTG |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|
|