SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 T-SQL Math problem?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

TheKai
Starting Member

16 Posts

Posted - 06/08/2013 :  17:18:48  Show Profile  Reply with Quote
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 - 06/08/2013 :  17:47:14  Show Profile  Reply with Quote
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 - 06/08/2013 :  17:56:23  Show Profile  Reply with Quote
*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

USA
5071 Posts

Posted - 06/09/2013 :  04:12:29  Show Profile  Visit russell's Homepage  Reply with Quote
http://www.youtube.com/watch?v=Pvvcz9bUQu4
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000