Menu

#4 ExpressionEvaluator treating doubles as strings

open
nobody
None
5
2006-09-06
2006-09-06
Anonymous
No

I'm using code to test some strings and the evaluator
is treating my Facts as strings. but i have them
declared as typeof(double). the following

F1+F2 is ouputing 100200 where it should be 300. I
think either you should check the valueType from the
symbol objects or do something like below...

double o1, o2;

object replacement;
try
{
//o1 = op1.value.Value;
//o2 = op2.value.Value;

if (double.TryParse
(op1.value.Value.ToString(), out o1) && double.TryParse
(op2.value.Value.ToString(), out o2))
{
replacement = o1 + o2;
}
else
{
replacement =
op1.value.Value.ToString() + op2.value.Value.ToString
();
}
/*if (o1 is string || o2 is string)
replacement = o1.ToString() +
o2.ToString();
else if (o1 is double && o2 is double)
replacement = (double)o1 + (double)
o2;
else
throw new Exception("only to be
caught");*/
}

basically im using the double.TryParse to convert to
strings to see if the symbol values are doubles and if
they are then adding else concating. I assume you
might want to do something like this for all the
operations.

Discussion


Log in to post a comment.

MongoDB Logo MongoDB