VilleLipponen
VilleLipponen

Reputation: 656

How to left-pad double with zeroes in Java

I need to pre-pend a number of zeroes to a double value in Java. It is simple with integers, for example:

System.out.printf("%08d\n", 1);

Produces: 00000001

If i try the same with a real value:

System.out.printf("%08f\n", 1.1);

The produced output is 1.100000

How do i achieve 0000001.1 ?

Thanks.

Upvotes: 2

Views: 3173

Answers (1)

Jaydeep Rajput
Jaydeep Rajput

Reputation: 3683

Try this

System.out.println(String.format("%07.1f",1.1F));

Upvotes: 3

Related Questions