C ++ Equivalent to% ld in Java for String.format ()

For example, %11.2lf in C ++ becomes %11.2f in Java. How about a long format?

+56
java string.format
Jan 6
source share
2 answers

As you may have developed, there is no need to specify the l flag. According to docs , a decimal integer is defined by d just like in C ++. So the answer is just %d .

+78
Jan 06 '10 at 8:45
source share

Use %d for decimal places (long, int). It is working fine. For example:

 System.err.println(String.format("%d", 193874120937489387L)); 

... will print just fine. Read java.util.Formatter details. %d will accept long , no problem.

+36
Jan 6
source share



All Articles