Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Power(n,n) result VS Windows Calculator
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

6 Posts

Posted - 03/05/2014 :  21:56:52  Show Profile  Reply with Quote
Hello guys

i would like to ask why the result from Power function of sqlserver is different from the windows calculator for example


SELECT POWER('1.0116666666666667','120')

RESULT IS: 4.02247064115812

1.0116666666666667 ^ 120

RESULT IS:4.0224706411581114419518589580497

Is there a way to compute result like windows calc from sqlserver coz
i'm having different result when i run my script using Power function at the end of result i got -0.01 instead of 0.00

i need your help please i been doing this for 2 weeks still i got negative result

thanks guys

Yak Posting Veteran

71 Posts

Posted - 03/06/2014 :  11:04:29  Show Profile  Reply with Quote
Can you edit your script? If yes, then limit the power portion to the same number of decimals SQL is showing. e.g CAST ... AS NUMERIC(20,14)

Not an Expert, Just a learner.

Edited by - maunishq on 03/06/2014 11:04:58
Go to Top of Page

Flowing Fount of Yak Knowledge

4614 Posts

Posted - 03/06/2014 :  11:26:39  Show Profile  Reply with Quote
I don't think there is much you can do other than write your own Power function. The built-in function uses a float. Since that is an approximate data type, you won't get very precise results.
Go to Top of Page

Flowing Fount of Yak Knowledge

4614 Posts

Posted - 03/06/2014 :  11:33:55  Show Profile  Reply with Quote
I was just curious so I wrote a quick loop to see what the results would be. Due to the way SQL Server handles Decimal/Numeric multiplication you need to set the scale really high to get a precise result:
DECLARE @Val DECIMAL(38, 37) = 1.0116666666666667;
DECLARE @Exponent INT = 120;
DECLARE @Result DECIMAL(38, 37);

WHILE @Exponent - 1 > 0
	SET	@Result = 
			WHEN @Result IS NULL THEN @Val * @Val
			ELSE @Result * @Val
	SET @Exponent = @Exponent - 1

SELECT @Result

RESULT: 4.0224706411581114419518589580496877300
Go to Top of Page
  Previous Topic Topic Next 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.02 seconds. Powered By: Snitz Forums 2000