- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Left pad an integer in Java with zeros
Let us see an example first to understand how an integer looks with left padding −
888 //left padding with spaces 0000000999 //left padding with 7 zeros
Let us see an example to left pad a number with zero −
Example
public class Demo { public static void main(String[] args) { int val = 9899; System.out.println(String.format("%05d",val)); } }
Output
09899
Let us see another example that pads a greater number of zeros −
Example
public class Demo { public static void main(String[] args) { int val = 9899; System.out.println(String.format("%010d", val)); } }
Output
0000009899
- Related Articles
- Left pad a String in Java with zeros
- Left pad a string in Java
- Left pad a String with a specified String in Java
- Left pad a String with a specified character in Java
- Left pad a String with spaces (' ') in Java
- Pad the values of the column with zeros in MySQL
- How to pad a number with leading zeros in JavaScript?
- How do you separate zeros from non-zeros in an integer array using Java?
- MySQL number-string formatting to pad zeros on the left of a string with numbers after a slash
- Create an integer column in an R data frame with leading zeros
- How do you fill in or pad a column with zeros using a MySQL query?
- MySQL left padding with zeros separated by hyphen?
- Return the numeric string left-filled with zeros in Numpy
- Golang Program to pad a string with 0's on left side
- How to Add or Pad Leading Zeros to Numbers or Text in Excel?

Advertisements