Search code examples
crystal-reportshideleading-zero

Crystal Report add leading zeros but do not show for sorting calculated field in group


I have a calculated field in Crystal Report which starts with numbers and is already sorted as text. I want to sort it like numbers. The calculated field consists of two numberfields and a textfield. Like this:

{numberfield1} & "." & {numberfield2} & " " & {textfield}

The Report shows the data like this (already sorted):

1.2 sometext  
10.3 sometext  
2.30 sometext  
2.4 sometext

What I want to achive is to sort first for {numberfield1} and then {numberfield2} with following result:

1.2 sometext  
2.4 sometext  
2.30 sometext  
10.3 sometext

I already tried this:
http://www.crystalreportsbook.com/Forum/forum_posts.asp?TID=19668
so my code looks like this:

totext({numberfield1},"00", 0) & "." &  
totext({numberfield2},"00",0) & " " &  
{textfield}

As far as I understand, this code should hide the leading zeros. But it does not. The leading zeros are still displayed in the report. At least, the sorting is working. The result:

01.02 sometext  
02.04 sometext  
02.30 sometext  
10.30 sometext  

I also tried:
cstr(val({numberfield}))
totext(tonumber({numberfield}))
These remove the leading zeros, but the sorting does not work.

Thank you very much for your time!


Solution

  • Create a first formula. Let's call it "TheOneThatYouSee":

    {numberfield1} & "." & {numberfield2} & " " & {textfield}
    //i just copied your formula
    

    Create a second formula. Let's call it "TheOneThatYouDoNotSee":

    totext({numberfield1},"00", 0) & "." &  
    totext({numberfield2},"00",0) & " " &  
    {textfield}
    //i just copied your formula
    

    Then you sort by TheOneThatYouDoNotSee (group by).

    Then you put the TheOneThatYouSee in the details section.