SAP Knowledge Base Article - Public

1204707 - Rounding Precision of 16th Decimal places in Crystal Reports

Symptom

  • When using numbers or doubles in a calculation, the result might not always evaluate to 0 as expected.

Here is an example:

1533.880000000000000
1
1533.880000000000000
1917.340000000000000
1
1917.340000000000000
127.820000000000000
-1
-127.820000000000000
127.820000000000000
-1
-127.820000000000000
127.820000000000000
-1
-127.820000000000000
127.820000000000000
-1
-127.820000000000000
127.820000000000000
-1
-127.820000000000000
312.460000000000000
-1
-312.460000000000000
312.460000000000000
-1
-312.460000000000000
312.460000000000000
-1
-312.460000000000000
312.460000000000000
-1
-312.460000000000000
312.460000000000000
-1
-312.460000000000000
312.460000000000000
-1
-312.460000000000000
312.460000000000000
-1
-312.460000000000000
312.460000000000000
-1
-312.460000000000000
312.440000000000000
-1
-312.440000000000000
      Remainder
 
-0.000000000000796
 

The above example provides an balancing calculation of two big debits which are being reduced by several smaller credits. The result is supposed to evaluate to 0.

 

Environment

  • SAP Crystal Reports 2008
  • SAP Crystal Reports 2011
  • SAP Crystal Reports 2013
  • SAP Crystal Reports 2016

Cause

Numbers / Doubles are both real floating-point number types, and are susceptible to roundoff errors. The problem is that floating point number values cannot be represented exactly in binary (eg. 1533.88). Crystal Reports is capable of having 15th significant digits of decimal precision and so the value 1533.88 is represented accurate to 15 digits.

Likewise, this is the case for the values 1917.34. Note that both of these binary representations are approximations, with some roundoff error at the 16th digit, because of the limitations of a 32bit floating point roundoff errors.

Resolution

The result of the sum, which shows the remainder can be rounded. The following formula will enable the result to evaluate to 0:

     Round (Sum (DebitOrCredit)

 This calculation will round the total of the subtrations in the above example.

Keywords

Rounding;Double;Number;Rounding;Precision , 7830542 , KBA , BI-RA-CR , Crystal Reports designer or Business View Manager , Problem

Product

Crystal Reports 2008 V1 ; SAP Crystal Reports 2013 ; SAP Crystal Reports 2016 ; SAP Crystal Reports XI ; SAP Crystal Reports XI R2