How to get a float result by dividing two integer values using T-SQL?

Using T-SQL and Microsoft SQL Server I would like to specify the number of decimal digits when I do a division between 2 integer numbers like: select 1/3 That currently returns 0. I would like it to return 0,33. Something like: select round(1/3, -2) But that doesn’t work. How can I achieve the desired result? … Read more

Why does integer division yield a float instead of another integer?

Consider this division in Python: Python 3.1 (r31:73574, Jun 26 2009, 20:21:35) [MSC v.1500 32 bit (Intel)] on win32 Type “help”, “copyright”, “credits” or “license” for more information. >>> 2/2 1.0 Is this intended? I strongly remember earlier versions returning int/int = int. What should I do? Is there a new division operator or must … Read more

Is multiplication and division using shift operators in C actually faster?

Multiplication and division can be achieved using bit operators, for example i*2 = i<<1 i*3 = (i<<1) + i; i*10 = (i<<3) + (i<<1) and so on. Is it actually faster to use say (i<<3)+(i<<1) to multiply with 10 than using i*10 directly? Is there any sort of input that can’t be multiplied or divided … Read more