Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Excel formula in c# (^) symbol

Tags:

c#

excel

I was trying to convert this excel code to c#

IF(D5=F5,ROUND(((SQRT(F5) +0.0833) ^2),0)

and the output for the excel file i'm getting is 19423

but when i use the same code for c#

D5 = 19400.25
F5 = 19400.25
string s = Math.Round(Convert.ToDecimal(Convert.ToInt32((Math.Sqrt(F5) + 0.0833)) ^ 2)).ToString();

I'm getting the output as 137. I don't know where I'm going wrong I tried each and everything and got stuck to this thing.Can anyone please help me ? Thanks is advance.

like image 992
George Avatar asked Oct 29 '25 19:10

George


1 Answers

The ^ symbol doesn't resemble the power function, as in Excel. You can't just translate this one-on-one. The C# ^ symbol does a bitwise exclusive-OR.

The actual C# code you should use to translate this function:

result = Math.Pow(Math.Sqrt(F5) + 0.0833, 2);
like image 62
Patrick Hofman Avatar answered Nov 01 '25 10:11

Patrick Hofman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!