Format floating point number with leading zeros [duplicate]

Number after %0 here defines full width including decimal point, so you need to change it to 7:

System.out.format("%07.3f", 1.23456789);

Leave a Comment