Description
The ToDoubleEval
method is a static extension method in the SandboxSystemExtensions
class. It attempts to evaluate a given string expression as a double-precision floating-point number. If the evaluation fails, it returns a specified default value.
Usage
Use this method when you need to safely evaluate a string expression to a double. This is particularly useful when dealing with user input or data that may not always be in a valid numeric format. The method provides a fallback mechanism by returning a default value if the evaluation is unsuccessful.
Example
// Example usage of ToDoubleEval
string expression = "3.14 + 2.71";
double defaultValue = 0.0;
double result = SandboxSystemExtensions.ToDoubleEval(expression, defaultValue);
// result will be 5.85 if the expression is valid, otherwise 0.0