%ld 在 Java 中的 C++ 等价于 String.format()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2011720/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 02:30:31 来源:igfitidea点击:
C++ Equivalent of %ld in Java for String.format()
提问by Milli
For instance, %11.2lf
in C++ becomes %11.2f
in Java.
How about for long format?
例如,%11.2lf
在 C++ 中变成%11.2f
在 Java 中。长格式怎么样?
采纳答案by Andrzej Doyle
回答by Stu Thompson
Use %d
for decimals (long, int). It works OK. E.g.:
使用%d
的小数(长,INT)。它工作正常。例如:
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.
...会打印得很好。请继续阅读以java.util.Formatter
了解更多详情。 %d
会用long
,没问题。