DataTable Compute for Minimum可能会忽略负值或执行隐式ABS [英] DataTable Compute for Minimum is possibly ignoring negatives or doing an implicit ABS

查看:94
本文介绍了DataTable Compute for Minimum可能会忽略负值或执行隐式ABS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以纠正DataTable为Minimum工作的计算方式吗?似乎正在使用Math.Abs​​处理负数,因此仅返回正值.

Can some one correct the way DataTable compute for Minimum works? It seems to be treating negatives with a Math.Abs and hence only positive values are returned.

推荐答案

Lavanya Deepak,

Hi Lavanya Deepak,

谢谢您在这里发布.

对于您的问题,我举一个简单的例子来验证.它将返回带有负数的最小值.

For your question, I make a simple example to verify. It will return the min value with negative number. 

在设计器中.

这是代码.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DataTable_min
{
    public partial class Form1 : Form
    {
        DataTable table;
        public Form1()
        {
            InitializeComponent();
            table = new DataTable("myTable");
            table.Columns.Add("Number", typeof(double));
            table.Rows.Add(0);
            table.Rows.Add(-1);
            table.Rows.Add(1);

        }
        private void button1_Click(object sender, EventArgs e)
        {
            double maxValue = (double)table.Compute("Min([Number])", ""); //computing the max value
            textBox1.Text =Convert.ToString(maxValue);
        }
    }
}

这是输出.

我希望这会对您有所帮助.

I hope this would be helpful to you.

如果还有其他问题,请随时与我们联系.

If you have something else, please feel free to contact us.

最好的问候,

温迪


这篇关于DataTable Compute for Minimum可能会忽略负值或执行隐式ABS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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