简体   繁体   中英

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

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

As you may have worked out, it's not necessary to specify the l flag. According to the docs , a decimal integer is specified by d just like in C++. So the answer is just %d .

Use %d for decimals (long, int). It works OK. Eg:

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

...will print just fine. Read up on java.util.Formatter for more details. %d will take a long , no problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM