Question
· Sep 16

padding zeros to the desired length

I receive a number as input

length = ln = 7

if input = 25
I need to add zeros to make make it as - 0000025 (a total length of ln)

if input = 9
I need to add zeros to make make it as - 0000009 (a total length ofln)

Discussion (5)3
Log in or sign up to continue

Assuming, your input value is an integer, you have , along with the other solutions, one more:

// this works as long as len  < 145
//
set len =  120
set inp = 12345
write $e(1E120_inp,*-len+1,*)

// of course, if the len is shorter than, say 10,
// then you can use smaller constans like
//
set len=10
set inp=9
write $e(1E10_inp,*-len+1,*)

A good (or even a bad) side effect of the above solution is, if you get an input value which is LONGER than the length, it will be truncated to the given length