Skip to Content

How to display tiled sign when more then two decimal places

Hello Team,

We have received a requirement like below. Suppose we are printing one number field which contains the decimal places(i.e it may contain 2 or 4 or 10 or up to 14 decimal places).

My requirement is if the if the number contains more then two decimal places we need to display tiled symbol after two decimal places. Please let us know how can we achieve this.

Ex.

10.12354 is the original value

We need to display it like 10.12~

Thanks,

Chakradhar

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Dec 19, 2018 at 08:16 PM

    I would use a formula to convert the number to a string, trim off trailing 0's, and then get the length of the part after the decimal point to determine whether to show the tile. The formula might look like this:

    {@ShowTile}
    WhilePrintingRecords;
    StringVar numstr := ToText({field},14, "",'.');
    NumberVar i;
    numstr := Split(numstr, '.')[2]; //get the part after the decimal
    i := length(numstr);
    Do While (i > 0) and (numstr[i] = 0)
      i := i - 1;
    Loop;
    i > 2  //If there are more than 2 non-zero characters after the decimal point, return true, else return false

    Put your tile image on the report where it needs to be. Right-click on it and go to "Format object...". Click on the formula button to the right of the "Suppress" checkbox (DO NOT check the checkbox!) and enter the following:

    not {@ShowTile}

    This will suppress the image if the decimal length is 2 or less.

    -Dell

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 20, 2018 at 02:12 PM

    Hi Chakradhar,

    Create a formula with this code:

    numbervar x := {number_field}; //Replace this field with the number field from your data source
    numbervar intg := int(x);
    stringvar dec := strreverse(totext(tonumber(strreverse(split(totext(x,3),'.')[2])),'#'));
    totext(intg,'#') & if dec <> '0' then '.' & left(dec,2) & if len(dec) > 2 then "~"

    -Abhilash

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 26, 2018 at 10:36 AM

    Hello Abhilash,

    Thanks for the replay we have tried it is working as expected up to 10 decimal places, but we need it for 14 decimal places. If we change from 10 to 12 getting an error like "crystal reports the number of decimal places is too large or not an integer". Please suggest us if you have any solution.

    Thank you.

    Chakradhar

    Add comment
    10|10000 characters needed characters exceeded

    • I believe, Crystal Reports has a limit of 15 or 16 digits, however, I'm not completely sure.

      If you're receiving that error, the only workaround would be to convert that number to a string (using a Command SQL or SQL Expression).

      The formula would also have to be modified if the field is a string.

      -Abhilash