0

I am working right now for a project using velocity.

We have a ticketnumber to create with a pattern. The ticket number has 8 or more chars and I need to insert leading zeros up to 11 chars.

$ticketNumber = 15464587 

I would like to convert this number to 00015464587 up to 11 chars dynamically.

Imagine the number is 199999990 so I have 9 chars instead of 8. I would need to insert two leading zeros this time instead of three.

How can I do this?

I tried with .size() function but I don't get a result.

marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
ramon guardia
  • 65
  • 1
  • 2
  • 13

1 Answers1

0

In python the below code will do your work -

final_len = 11 
ticketNumber = 15464587
add_zero = ''

if len(str(ticketNumber))<final_len:
    diff = final_len - len(str(ticketNumber))
    for i in range(diff):
        add_zero = add_zero+str(0)
    velocity = add_zero + str(ticketNumber)
print(velocity)

output of the code is - 00015464587

Pankaj Mishra
  • 450
  • 6
  • 15