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
  • 732,580
  • 175
  • 1,330
  • 1,459
ramon guardia
  • 75
  • 1
  • 3
  • 13
  • you can use java https://stackoverflow.com/questions/473282/how-can-i-pad-an-integer-with-zeros-on-the-left – Ori Marko Apr 30 '20 at 08:28

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
  • 445
  • 6
  • 15