search
Login

Categories


C Books Guide and List
C++ Books Guide and List
Best Java Books

3.8k questions

4k answers

117 comments

10.7k users

0 votes
127 views
asked Expert 11.4k points 14 22 28

1 Answer

0 votes
0 padds output with zeros rather than spaces.

Syntax

fmt.format("0%g\n", 123.1);

Example

The 0 flag causes output to be padded with zeros rather than spaces.

import java.util.Formatter;
public class Main {
  public static void main(String args[]) {
    Formatter fmt = new Formatter();
    fmt.format("0%g\n", 123.1);

  }
}
The output:
0123.100
answered Sr Member 3.9k points 5 8 12

Related questions

0 votes
1 answer 184 views
184 views
How do you left pad an int with zeros in java when converting to a string? I'm basically looking to pad out integers up to 9999 with the leading zeros. E.g. 1 = "0001"
asked anonymous
0 votes
1 answer 21 views
0 votes
2 answers 18 views
18 views
Is there some easy way to pad Strings in Java? Seems like something that should be in some StringUtil-like API, but I can't find anything that does this.
asked john Guru 27.1k points 31 50 97
0 votes
1 answer 92 views
92 views
asked augustaina Sr Member 4.8k points 10 25 31
0 votes
1 answer 104 views
104 views
asked augustaina Sr Member 4.8k points 10 25 31
...