0

I try to format integers so they always have four proper digits, that is, I want 0s for padding.

I have tried "%04d" which works nicely for positive number. For negatives it gives things like -[854] where I need -[0854].

Thank you.

5

1 Answer 1

1
if(number>=0){ 
    String.format("%04d",number); 
}else{
     String.format("%05d",number); 
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.