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.
Unfortunately, activation email could not send to your email. Please try again.

How to correct div/0 in class CalcQuickBase

Thread ID:





127643 Nov 30,2016 01:53 AM Dec 5,2016 03:57 AM Windows Forms 8
Tags: Calculate
Asked On November 30, 2016 01:53 AM

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 04:31 AM

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 04:46 AM

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 07:23 AM

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 09:07 AM

Thanks, I'll try this solution

Replied On December 1, 2016 10:06 AM

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 06:16 AM

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 09:09 AM

Thanks, it helped.

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

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.

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.