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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Infinity is not a valid value for Decimal

Thread ID:

Created:

Updated:

Platform:

Replies:

129489 Mar 21,2017 10:09 PM UTC Mar 22,2017 09:37 AM UTC WinForms 1
loading
Tags: GridGroupingControl
Josip Pejakovic
Asked On March 21, 2017 10:09 PM UTC

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?

Arulpriya Ramalingam [Syncfusion]
Replied On 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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;