We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Infinity is not a valid value for Decimal

Hello,

I have one Expression column in grid grouping control. It showe result of dividing two numbers from two other columns. Unfortunately sometime those columns contains zeros so dividing is impossible. Anyhow I need to display data in grid so I'm wondering is there any way to avoid this error and display records?

1 Reply

AR Arulpriya Ramalingam Syncfusion Team March 22, 2017 09:37 AM UTC

Hi Josip, 

Thanks for your interests in Syncfusion products. 

By default, Decimal return type does not support the infinity results. To overcome this issue, set the return type as Double for the ExpressionFieldDescriptor. Already we have provided the KB for this scenario. Please make use of below link, 

 
Note 
If you want to return any message in ExpressionField instead of returning “0” or “infinity”, Custom method can be used to customize the Formula for ExpressionField. Please make use of below code and sample, 

Code snippet 
 
Custom method  
//DividedValue that returns DivideByZero if any of the argument value is zero else returns divided value 
private string DividedValue(string args) 
{ 
    // Get the list delimiter (for en-us, it is a comma). 
    char comma = Convert.ToChar(this.gridGroupingControl1.Culture.TextInfo.ListSeparator); 
    string[] arguments = args.Split(comma); 
   decimal arg1, arg2; 
 
    if (decimal.TryParse(arguments[0], System.Globalization.NumberStyles.Any, null, out arg1) 
&& decimal.TryParse(arguments[1], System.Globalization.NumberStyles.Any, null, out arg2)) 
    { 
        //returns DivideByZero if any of the column value is zero 
        if (arg1 == 0 || arg2 == 0) 
        { 
            return "DivideByZero"; 
        } 
        else 
            return Math.Abs(arg1 / arg2).ToString(); 
    } 
    return "Invalid input"; 
} 
 
 
Adding the custom method to Grid 
//Adding Custom function to Expression Field 
this.gridGroupingControl1.TableDescriptor.ExpressionFieldEvaluator.AddFunction("Divide", new ExpressionFieldEvaluator.LibraryFunction(DividedValue)); 
 
// Adding the Expressions using DividedValue function. 
ExpressionFieldDescriptor expField = new ExpressionFieldDescriptor("Divide", "Divide([CategoryName],[CategoryID])", typeof(System.String)); 
 
//Adding the custom ExpressionField to Grid 
this.gridGroupingControl1.TableDescriptor.ExpressionFields.Add(expField); 

Screenshot 
 



Regards, 
Arulpriya 


Loader.
Live Chat Icon For mobile
Up arrow icon