
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Display numbers with leading zeroes in Java
To display numbers with leading zeros in Java, useDecimalFormat("000000000000").
Let us first set the format with DecimalFormat class −
DecimalFormat decFormat = new DecimalFormat("000000000000");
Now, let us display some numbers with leading zeros −
String res = decFormat.format(298989); System.out.println(res); res = decFormat.format(565); System.out.println(res);
The following is an example −
Example
import java.text.DecimalFormat; public class Demo { public static void main(String args[]) { DecimalFormat decFormat = new DecimalFormat("000000000000"); String res = decFormat.format(298989); System.out.println(res); res = decFormat.format(565); System.out.println(res); res = decFormat.format(38989); System.out.println(res); res = decFormat.format(78768768); System.out.println(res); res = decFormat.format(298989); System.out.println(res); } }
Output
000000298989 000000000565 000000038989 000078768768 000000298989
- Related Questions & Answers
- JavaScript Regex to remove leading zeroes from numbers?
- Explain how to remove Leading Zeroes from a String in Java
- Remove Leading Zeroes from a String in Java using regular expressions
- Display numbers with thousands separator in Java
- How to preserve leading 0 with JavaScript numbers?
- How to display numbers in scientific notation in Java?
- Remove Leading Zeros From String in Java
- Java Program to Remove leading zeros
- Move Zeroes in Python
- How to display random numbers less than 20 in Java
- Java Program to Display Prime Numbers Between Two Intervals
- Print leading zeros with C++ output operator
- How to display numbers with decimal in R data frame column?
- Java Program to Display Prime Numbers Between Intervals Using Function
- Java Program to Display Armstrong Numbers Between Intervals Using Function
Advertisements