简体   繁体   English

Excel公式转换为PHP编辑:如何在PHP中使用^

[英]Excel formula to PHP edit: How to use ^ in PHP

I have an Excel formula 我有一个Excel公式

=180*((B10/B9)*(((B10/B9)^2+((B12/B9)*2)^2)^-0,5)*BOOGTAN((((B10/B9)^2+((B12/B9)*2)^2)^-0,5))+((B10/B9)/WORTEL(1+((B12/B9)*2)^2))/(B10/B9)*BOOGTAN((B10/B9)/WORTEL(1+((B12/B9)*2)^2)))/(2*PI())

Which I converted to PHP 我将其转换为PHP

$straling = 180*(($gevelhoogte/$gevelbreedte)*((($gevelhoogte/$gevelbreedte)^2+(($afstand/$gevelbreedte)*2)^2)^-0.5)*atan(((($gevelhoogte/$gevelbreedte)^2+(($afstand/$gevelbreedte)*2)^2)^-0.5))+(($gevelhoogte/$gevelbreedte)/sqrt(1+(($afstand/$gevelbreedte)*2)^2))/($gevelhoogte/$gevelbreedte)*atan(($gevelhoogte/$gevelbreedte)/sqrt(1+(($afstand/$gevelbreedte)*2)^2)))/(2*PI());

But now, for some reason the outcome isn't equal. 但是现在,由于某种原因,结果并不相等。 I expect it has somethingto do with (( vs )). 我希望它与((vs))有关。

Can someone please help here? 有人可以帮忙吗?

You can't use ^ in PHP, as the ^ operator is the bitwise XOR operator in PHP. 您不能在PHP中使用^ ,因为^运算符是PHP中按位XOR运算符。 In order to use "to the power of" function, you need to use the pow(x,y) function in PHP, which gives "x to the power of y". 为了使用“至幂”函数,需要在PHP中使用pow(x,y)函数,该函数将“ x赋予y的幂”。

In short, you need to use this formula: 简而言之,您需要使用以下公式:

$straling = 180*(($gevelhoogte/$gevelbreedte)*(pow(pow($gevelhoogte/$gevelbreedte,2)+pow(($afstand/$gevelbreedte)*2,2),-0.5))*atan((pow(pow($gevelhoogte/$gevelbreedte,2)+pow(($afstand/$gevelbreedte)*2,2),-0.5)))+(($gevelhoogte/$gevelbreedte)/sqrt(1+pow(($afstand/$gevelbreedte)*2,2)))/($gevelhoogte/$gevelbreedte)*atan(($gevelhoogte/$gevelbreedte)/sqrt(1+pow(($afstand/$gevelbreedte)*2,2))))/(2*PI());

From your variable names I assume youre Dutch, but I'll keep this in English since other users will able to read then too ;) 从您的变量名中,我假设您是荷兰人,但是我将用英文保留该名称,因为其他用户也可以阅读;)

Maybe you'll find this PHP library useful! 也许您会发现此PHP库很有用! http://phpexcel.codeplex.com/ There is a calculation module in there that will handle a lot of different ExcelFormulas. http://phpexcel.codeplex.com/那里有一个计算模块,可以处理许多不同的ExcelFormulas。

Since your formula is quite complex, I am not sure if it will handle correct. 由于您的公式非常复杂,因此我不确定它是否会正确处理。 But give it a try I'd say. 但请尝试一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM