zero-pad

Zero-pad digits in string

Hi I need to cast single figures (1 to 9) to (01 to 09). I can think of a way but its big and ugly and cumbersome. I'm sure there must be some concise way. Any Suggestions ...

Left padding integers with zeros in Java

How do you left pad an int with zeros in java when converting to a string? I'm basically looking to pad out integers up to 9999 with the leading zeros. E.g. 1 = "0001" I know this is probably simple and as a parallel task I'm googling it, but SO is super quick when it comes to inane questions I should know the answer to... ...

How can I count the digits in an integer without a string cast?

I fear there's a simple and obvious answer to this question. I need to determine how many digits wide a count of items is, so that I can pad each item number with the minimum number of leading zeros required to maintain alignment. For example, I want no leading zeros if the total is < 10, 1 if it's between 10 and 99, etc. One solution w...

In PHP, how do I add to a zero-padded numeric string and preserve the zero padding?

If I have a variable in PHP containing 0001 and I add 1 to it, the result is 2 instead of 0002. How do I solve this problem? ...

Zero-padding a spinner in Java

How do you add zero padding to a JSpinner? Since the spinner creates the JFormattedTextField itself, I can't just pass the format into the JFormattedTextField constructor. Isn't there a way to set the formatting on an existing JFormattedTextField? What I want: value = 37, editor = "0037" UPDATE: I have tried this as suggested: JSpin...