如何在C#中编写此方程式? [英] How do I write this equation in C#?

查看:173
本文介绍了如何在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)
      }


这篇关于如何在C#中编写此方程式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆