简体   繁体   English

JAVA:System.out.format的多种格式

[英]JAVA: Multiple formats for System.out.format

I'm attempting to format my double integers to be spaced out, and have two 0's at the end rather then one. 我试图将我的双整数格式化为间隔,并且在结尾处有两个0而不是一个。

My code: 我的代码:

System.out.format(%-10s", double);

That works perfectly for spacing out the double for what i'm doing. 这对于我正在做的事情来说是完美的。

I then use 然后我用

System.out.format(%.2f", double);

To properly display the double with two integers. 要正确显示带有两个整数的double。

My problem is i can't seem to combine both of these formatters to work on one double. 我的问题是我似乎无法将这两种格式化程序结合起来使用一个双。 For instance: 例如:

System.out.format(%-10s %.2f", double);

To display something like "{the proper space} double.00" 要显示类似“{the space space} double.00”的内容

They work perfectly when i only use one, but i can't seem to figure out how to use both on the same double. 当我只使用一个时它们完美地工作,但我似乎无法弄清楚如何在同一个双倍使用它们。 Sorry if i'm vague, i'm very limited on time atm and need to finish this quickly. 对不起,如果我很模糊,我的时间非常有限,需要快速完成。

This code ... 这段代码......

System.out.format("<%-10s>\n", "a");
System.out.format("<%10f>\n", 0.2);
System.out.format("<%-10f>\n", 0.2);
System.out.format("<%10.2f>\n", 0.2);
System.out.format("<%-10.2f>\n", 0.2);

... shows ... ...显示......

<a         >
<  0,200000>
<0,200000  >
<      0,20>
<0,20      >

... is the last one that what you are looking for? ...是你要找的最后一个?

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

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