String val = "98"
I need to get the output as 0000098
(7 digits).
I need left padding of zeros to the string or integer value...
The number stored in val is dynamic and may contain any number of digits, but the output should always be 7 digits.
Use String.format
:
public class A {
public static void main(String[] args) {
System.out.println(String.format("%07d", 98)); // -> 0000098
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With