I do not understand well your problem. However I will put some ideas:
This code gives compiling errors because it does not know in advance the type of val:
Value val = 35;
double res = val/2;
This one works:
Value val = 35;
double res = int(val)/2.;
This one works too:
Value val = 35;
double res = double(val)/2.;
But this one will fail in runtime with an Assertion:
Value val = "35";
double res = double(val)/2.;
If you want to avoid an Assertion but your code could put an inappropriate value in Value, you can do this:
Value val = "35";
double res;
if (IsNumber(val))
res = int(val)/2.;
else
res = -1; // You can put here and exception, an Exclamation, a return false, ...