SAP Knowledge Base Article - Public

2372508 - Summary value changes depending on the user opening the report in Crystal Reports

Symptom

  • Summary changes.
  • Some user see larger or lower summary values.
  • Numeric values different in Crystal Reports, depending on which computer the report with saved data is open.
  • When converting a string containing numeric value to a number, using the function ToNumber, it returns different values in Crystal Reports designer versus when viewing the report in SAP BI LaunchPad.

Environment

  • SAP Crystal Reports 2013
  • SAP Crystal Reports 2016
  • SAP Crystal Reports 2020

Reproducing the Issue

  1. In Crystal Reports, create a report off any data source that contains numeric values stored in text format.
        
  2. Create a formula to convert the numeric text to number using the funtion "ToNumber" like:
        
        ToNumber({Numerical Text Database Field})
        
  3. Insert the formula on the report, and insert a summary on it.
        
  4. Refresh the report, and save it with data.
        
  5. When viewing the report on a different computer, or with a different user, notice the summary values are different.

Cause

  • This situation occurs due to the numeric text value has commas as a decimals separator, and the user viewing the report have different local setting, which cause the function "ToNumber" to convert the number differently, as it base the conversion on the local setting.
        
  • To better illustrate what's happening, let's use an example. 
       
    If we have a string of characters containing the value:
       123,456
        
    And we convert the string when the local setting is set to USA, then in the USA, the comma is considered as a thousand separator, and if we do not show the decimals, it will convert the string to the number:
       123456
         
    But for the same report, if the user local setting is set to France, then the comma is considered a decimal separator, and therefore the number will be converted to the following, if we do not show the decimals:
       123
           
    Both convertion are correct, depending on the regional setting, and by design, the function "ToNumber" uses the local setting to help converting a numerical string to number. It makes the function simple to use, but in this situation, it is causing the number to be converted incorrectly, because the comma is used for decimals separator. Unfortunately, there is no option to control what is a decimals character, and what is the thousands separator character when using the function ToNumber.

Resolution

  • To convert a numerical string that uses a comma as a decimal separator, and no character for thousand separator, regardless of the user local regional setting, create a formula using the following code:

       Local StringVar MyNumber := <INSERT YOUR NUMERICAL STRING FIELD HERE> ;

       Local NumberVar Output := 0;
       Local StringVar Array aNumber := Split(MyNumber,',');

       If uBound(aNumber) >= 1 Then
          If isNumeric(aNumber[1]) Then
             Output := Abs(ToNumber(aNumber[1]));

       If uBound(aNumber) = 2 Then
          If isNumeric(aNumber[2]) Then
             Output := Output + ToNumber(aNumber[2]) / ToNumber('1' + ReplicateString('0',Length(aNumber[2])));

       If "-" in aNumber[1] Then
          Output := Output * -1;

       Output;
        
          

    Note: Insert in the above code your numerical string field where it is written <INSERT YOUR NUMERICAL STRING FIELD HERE>

Keywords

number, CR , KBA , BI-RA-CR , Crystal Reports designer or Business View Manager , Problem

Product

SAP Crystal Reports 2013 ; SAP Crystal Reports 2016 ; SAP Crystal Reports 2020