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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to correct div/0 in class CalcQuickBase

Thread ID:





127643 Nov 30,2016 06:53 AM UTC Dec 5,2016 08:57 AM UTC WinForms 8
Tags: Calculate
Asked On November 30, 2016 06:53 AM UTC

formula a/b + c/d, when b or d 0 method ParseAndCompute return infinity.
How replace div/0 -> 0?

Kanimozhi Bharathi [Syncfusion]
Replied On December 1, 2016 09:31 AM UTC

Hi Alex,   
While calculating division on zero, CalcEngine returns “#Div /0!” error which is the same result as in MS Excel.  Your requirement can be achieved by using IF condition like below code example   
CalcQuickBase calc = new CalcQuickBase();   
calc["a"] = "5";   
calc["b"] = "0";   
calc["c"] = "4";   
calc["d"] = "2";   
var result = calc.ParseAndCompute("if([b] = 0, 0 , [a]/[b])+ if([d] = 0, 0 , [c]/[d])");   
Kanimozhi B    

Replied On December 1, 2016 09:46 AM UTC

If there is a complicated formula. It is necessary to add much function "if". Perhaps there is another way of “#Div /0!” error handling?

Kanimozhi Bharathi [Syncfusion]
Replied On December 1, 2016 12:23 PM UTC

Hi Alex, 
You can achieve your  requirement by defining the custom formula  and adding in CalcEngine LibraryFunction like below code example 
CalcQuickBase calc = new CalcQuickBase(); 
calc.Engine.AddFunction("Div", new Syncfusion.Calculate.CalcEngine.LibraryFunction(ComputeDivision)); 
var result1= calc.ParseAndCompute("Div(5, 0)"); 
//Implementation of function 
public string ComputeDivision(string range) 
    var args = range.Split(new char[]{CalcEngine.ParseArgumentSeparator}, StringSplitOptions.None); 
    if (args[1] == "0") 
        return "0"; 
    var parse = Int32.Parse(args[0])/Int32.Parse(args[1]); 
    return parse.ToString(); 
We have also prepared the sample for your reference. Please find the sample link below 
Kanimozhi B 

Replied On December 1, 2016 02:07 PM UTC

Thanks, I'll try this solution

Replied On December 1, 2016 03:06 PM UTC

with simple formula work, with formula like (a/b+c/d)/([k]/[l]+[j]) not work external div

Kanimozhi Bharathi [Syncfusion]
Replied On December 2, 2016 11:16 AM UTC

Hi Alex,  
We have modified the sample based on your requirement. Please find the below code example for your reference, 
CalcQuickBase calc = new CalcQuickBase();  
calc.Engine.AddFunction("Div", new Syncfusion.Calculate.CalcEngine.LibraryFunction(ComputeDivision));  
var result1= calc.ParseAndCompute("DIV((DIV(5,0)+ DIV(9,5)),(DIV(4,0) + 6))"); // (a/b + c/d)/(k/l + j]) 
//Implementation of function  
public string ComputeDivision(string range)  
    var args = range.Split(new char[]{CalcEngine.ParseArgumentSeparator}, StringSplitOptions.None);  
    string s1 = calc.Engine.GetValueFromArg(args[0]); 
    string s2 = calc.Engine.GetValueFromArg(args[1]); 
    if (s2 == "0")  
        return "0";  
    var parse = Int32.Parse(s1)/Int32.Parse(s2);  
    return parse.ToString();  
We have also prepared a sample for your reference and the link for the same has been given below  
Kanimozhi B  

Replied On December 2, 2016 02:09 PM UTC

Thanks, it helped.

Dinesh Babu Yadav [Syncfusion]
Replied On December 5, 2016 08:57 AM UTC

Hi Alex,
Thanks for the update.
​​​​​Dinesh BabuYadav


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.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

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