Search code examples
stringcrystal-reportsnumberssummary

Crystal Reports summary of a string field


I have the following formula named @newitemQuant:

WhileReadingRecords;
StringVar text := Totext ( {AR_SalesBySalesPersonDenim;1.quantity} , 6 , ""  )  ;  
NumberVar end  := length ( text ) ;
NumberVar clip :=

    (if  Val ( text [ end - 6 to end ] ) = 0 then 1 else 0 ) +
    (if  Val ( text [ end - 5 to end ] ) = 0 then 1 else 0 ) +
    (if  Val ( text [ end - 4 to end ] ) = 0 then 1 else 0 ) +
    (if  Val ( text [ end - 3 to end ] ) = 0 then 1 else 0 ) +
    (if  Val ( text [ end - 2 to end ] ) = 0 then 1 else 0 ) +
    (if  Val ( text [ end - 1 to end ] ) = 0 then 1 else 0 ) +
    (if  Val ( text [ end - 0 to end ] ) = 0 then 1 else 0 )  ;

text [ 1 to Length ( text ) - clip ]

This basically converts my database field {AR_SalesBySalesPersonDenim;1.quantity} with a NUMBER datatype to STRING before it manipulates with it. And on the report shows the resulting STRING.

Now I want to place a SUMMARY of resulting string field on the report. Can't achieve that.

I have tried using ToNumber() within the same formula as well as a new formula:

numbervar fVal;
fVal := ToNumber({@newitemQuant}). 

But no progress. Thanks in Advance


Solution

  • I found the answer.

    Basically to hanlde the number of decimals in your number on the report, just right click the field select Format Object -> Number tab -> in the Decimals formula -> enter

    If CurrentFieldValue = Int(CurrentFieldValue) Then
    0 
    else
    2
    

    Done. Where 2 is the max number of decimals you want to show in anycase.

    Thanks