Skip to main content
New Participant
Mar 21, 2023 8:05 PM UTC
Solved

Format a string value according to the requirement

Hi,

We have a requirement to generate a document which contains some information of a user that needs to be encoded by the guidelines provided. We need to format the value in such a way that it's length remains fixed always which is provided to us. So any value which has less digits than the required number of digits should be formatted like for eg: If the input is 1250000 and the max limit is 20, then it should be encoded as 00000000000001250000.

How can we do that, thanks in advance.

    stefanhelzle0001
    Brainy
    Mar 21, 2023 8:31 PM UTC

    Or, even shorter:

    text(ri!value, rept("0", ri!limit))

    In case that "value" is longer or alphanumeric you might want to use this:

    concat(
      rept("0", ri!limit - len(ri!value)),
      ri!value
    )

    3 replies

    sanchitg0002
    Inspiring
    Mar 21, 2023 8:11 PM UTC

    text() function is a perfect match for you

    text(ri!value, concat(repeat(ri!limit, 0)))

    Check out text() for more details.

    stefanhelzle0001
    Brainy
    Mar 21, 2023 8:31 PM UTC

    Or, even shorter:

    text(ri!value, rept("0", ri!limit))

    In case that "value" is longer or alphanumeric you might want to use this:

    concat(
      rept("0", ri!limit - len(ri!value)),
      ri!value
    )

    sanchitg0002
    Inspiring
    Mar 22, 2023 6:26 AM UTC

    Cool, didn't knew about that.