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

How can I resolve the exception occurred when division operation is used in ExpressionDescriptor?

Platform: WinForms |
Control: GridGroupingControl |
Published Date: January 27, 2015 |
Last Revised Date: November 13, 2015

Problem:

A decimal does not support unknown division operation, that is, any number divided by zero or zero divided by any number.

Reason:

A decimal number is a floating-point value that consists of a sign, a numeric value where each digit in the value ranges from 0 to 9, and a scaling factor that indicates the position of a floating decimal point that separates the integral and fractional parts of the numeric value.

The decimal number can be used for calculations under following criteria:

  • A Decimal is a 128-bit floating point data type,that should be used where precision is of extreme importance, such as monetary calculations. For more details, please refer this link: what-is-the-difference-between-decimal-float-and-double-in-net
  • One reason that NaN and Infinity values make more sense for floating point arithmetic is that the operations could result in division by zero, not only because the divisor is actually zero, but because it is too small to be represented by the type. For more details, please refer this link: why-is-nan-not-a-number-only-available-for-doubles

Solution:

To perform the division operation in the Expression Field, you can use Double, Integer type. Decimal return type does not support the NaN, Infinity results, because of the above criteria. It can be used only for exact numbers. When you want to perform the division operations while updating the data in the grid, you can use the Double or Integer types.

For example, assume you have a grid with expression columns, Column [A], Column [B] and Column [C]. The Expression column is calculated depending on the values of Column [A] and Column [B]. Exception is thrown when you add the data to the grid for one column, assuming it to be Column [A], it automatically calculates column [B] as zero. Then expression column automatically calculates division operation for Column [A] / 0, that is, column [B], so the result is Infinity.

C#

VB

Sample:

http://www.syncfusion.com/downloads/support/directtrac/general/Expression_Column_Result_Type_As_Double-43158780.zip

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

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

Up arrow icon

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

Live Chat Icon For mobile
Live Chat Icon