Append ".0" to the values in your equation:
string expression = "330200000.0*450000.0";
If, as you said, the equation has been entered as it is (i.e. without the ".0") by the user, then you might have to engage in some vaguely unpleasant string manipulation to achieve this. I came up with the following, although I'm certain it can be done better:
string expression = "330200000*450000"; // or whatever your user has entered
expression = Regex.Replace(
expression,
@"d+(.d+)?",
m => {
var x = m.ToString();
return x.Contains(".") ? x : string.Format("{0}.0", x);
}
);
var loDataTable = new DataTable();
var computedValue = loDataTable.Compute(expression, string.Empty);
The regular expression attempts to account for whether or not your user has already put a decimal on the end of any of the numbers within their equation.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…