C++相当于 Java 中 String.format() 的 %ld

发布于 2024-08-16 19:12:23 字数 77 浏览 4 评论 0原文

例如,C++ 中的 %11.2lf 在 Java 中变为 %11.2f。 长格式怎么样?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橘香 2024-08-23 19:12:23

正如您可能已经发现的那样,没有必要指定 l 标志。根据 文档,十进制整数由 d 指定,就像在 C++ 中一样。所以答案就是%d

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.

转角预定愛 2024-08-23 19:12:23

使用 %d 表示小数(long、int)。工作正常。例如:

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

...打印得很好。阅读 java.util .Formatter 了解更多详细信息。 %d 将需要long,没问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文