简体   繁体   English

C ++中用于String.format()的Java中%ld的等效项

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

For instance, %11.2lf in C++ becomes %11.2f in Java. 例如, %11.2lf在C ++变得%11.2f在Java中。 How about for long format? 长格式怎么样?

As you may have worked out, it's not necessary to specify the l flag. 正如您可能已经解决的那样,没有必要指定l标志。 According to the docs , a decimal integer is specified by d just like in C++. 根据文档 ,十进制整数由d指定,就像在C ++中一样。 So the answer is just %d . 所以答案只是%d

Use %d for decimals (long, int). 使用%d表示小数(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. 阅读java.util.Formatter以获取更多详细信息。 %d will take a long , no problem. %d需要很long ,没问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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