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
 General SQL Server Forums
 New to SQL Server Administration
 T-SQL Math problem?

Author  Topic 

TheKai
Starting Member

16 Posts

Posted - 2013-06-08 : 17:18:48
When I run the following code in MSSQL

SELECT (1.0 / (1.0 + POWER((1301.0 - 1200.0) / 400.0, 10.0) ) )
the result is 0.999...

When I run what I thought was the equivalent code in C#
double pro = (1.0 / (1.0 + Math.Pow(10.0, (1301.0 - 1200.0) / 400.0)));
I get the correct answer 0.35...

Can you enlighten me what I'm doing wrong with the SQL query for it to return 1 to me?

TheKai
Starting Member

16 Posts

Posted - 2013-06-08 : 17:47:14
So, it seems to be that this kind of behavior might be seen if any of the values are treated as integers and some decimals were getting dropped somewhere along the way, thus giving a result of "approximately 1". But even if I explicitly CONVERT(float, number) every number in the SQL statement, I still get "~1" as a result instead of the expected "~0.35".
Go to Top of Page

TheKai
Starting Member

16 Posts

Posted - 2013-06-08 : 17:56:23
*embarrassed*
I thought the POWER parameters needed to be reversed in TSQL... seems like they are in the same order. It helps to read...
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2013-06-09 : 04:12:29
http://www.youtube.com/watch?v=Pvvcz9bUQu4
Go to Top of Page
   

- Advertisement -