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

Javastring.format

Java Problem Overview


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

Java Solutions


Solution 1 - Java

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.

Solution 2 - Java

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

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMilliView Question on Stackoverflow
Solution 1 - JavaAndrzej DoyleView Answer on Stackoverflow
Solution 2 - JavaStu ThompsonView Answer on Stackoverflow