Is it possible to exceed the int32 (into double) in DataColumn Expression?

时间:2017-01-30 14:22:36

标签: c#

I've tried to make a calculator which will cover most stuff like power by and parentheses using System.Data DataTable + Columns and just load the equation in there as a string. Example: 10/2+32-5*3... This to make it easier to code but I'm starting to think I should've done it another way.

When my friend and I wanted to test speed we exceeded the Int32 limit so now I wonder if it's possible to change it into the "double" limit? The column needs to be able to exceed Int32 before the "table.Columns.Add(columns)" line, That's where it crashes

    static double Calculate(string formula)
    {
        DataTable table = new DataTable();

        DataColumn column = new DataColumn();
        column.DataType = typeof(double);
        column.ColumnName = "Calculate";
        column.Expression = formula;

        table.Columns.Add(column); // Crash here and Exeption say Int32 limit exeeded

        table.Rows.Add(0);
        return Convert.ToDouble((table.Rows[0]["Calculate"]));
    }

1 个答案:

答案 0 :(得分:0)

是的,可以像往常一样将Int32转换为Double:

Convert.ToDouble((table.Rows[0]["Calculate"]));

但要注意将此值返回的变量类型。也就是说,变量的类型也必须是" Double"这样你就不会收到任何错误。

您可以从以下链接了解更多相关信息: https://msdn.microsoft.com/en-us/library/ayes1wa5(v=vs.110).aspx