in reply to increment # but keep # of digits same
What happens if you get to 9999? Do you wrap around? (If you don't get that high, you can probably ignore this post).
When the number goes past 9999, you can get the last four digits with the modulus operator ( $i % 10_000). However, for 10_000, you end up with 0, which may not make sense (but you just treat it as a special case and set it to 1).
You can't simply use sprintf() as others have suggested. A %4d format specifier does not limit the field to four columns: it only tries to set it in a four column field and it can overflow. It does not guarantee output of a particular width.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: increment # but keep # of digits same
by Anonymous Monk on Apr 27, 2005 at 09:13 UTC |