如何在C#中编写此方程式?
我需要为一些库计算3个方程.该库正用于为RuneScape游戏开发一些工具.这里是指向方程式的链接,以供参考: http://runescape.wikia.com/wiki/Combat_level#Combat_Formula [^ ]
我想尝试使函数的返回值采用十进制/浮点格式.
我尝试查找.NET和C#的数学解析引擎.我决定我不必也不应该做所有这些事情来解析某些方程式.
我尝试了几种类型的类型转换,并使用System.Convert类等等.根本没有运气.
这是我到目前为止所拥有的.
I have 3 equations I need to calculate for some libraries. The library is being used to develop some tools for the game RuneScape. Here''s a link to the equations for reference: http://runescape.wikia.com/wiki/Combat_level#Combat_Formula[^]
I would like to try and make the return value for the functions to be in decimal/float format.
I tried looking up math parsing engines for .NET and C#. I decided I didn''t and shouldn''t have to do all that to parse some equations.
I tried several forms of type casting, and using System.Convert class and so on. Simply no luck.
Here''s what I have so far.
public class PlayerLevelCalc
{
public float getMeleeCB(float attk,float str,float def,float hp,float pray)
{
return (Convert.ToSingle(Convert.ToDecimal("0.3f")*(1.3*(attk+str)+def+hp+(.5*pray))));
//Math.Round(.25,2,System.MidpointRounding.AwayFromZero);
}
public float getMagicCB(float mage,float def,float hp,float pray)
{
return (0);
}
如SA所说,请使用double.等式并不那么复杂,所以不确定为什么或您遇到什么问题吗?
As SA said use double. The equation is not that complex so not sure why or what you are having problems with?
public double getMeleeCB(double attk,double str,double def,double hp,double pray)
{
return math.floor((def + con + (pray / 2) + 1.3 * (attk + str)) / 4)
}