英文:
Does a floating point format's width option exclude the decimal point when it's the last element?
问题
我正在阅读关于printf的秘密以编写自己的printf的文档,并发现第二个"(%5.0f, e)",其中e = 2.718281828printf浮点格式及其输出令人困惑,为什么数字3和小数点前有四个空格?
我原以为输出应该是3.,数字3前有三个空格,因为小数点本身占据一个空格。
英文:
I'm reading this document about the secret of printf in order to write my own printf and I found the 2nd ("%5.0f.", e)
with e = 2.718281828 printf floating point format and what it produces confusing, why is there four spaces before the 3 and the decimal point?
I thought the output would be 3. with three spaces before the number 3 as the decimal point takes one space itself.
答案1
得分: 1
在格式字符串中 "%5.0f."
有两部分:一个浮点数格式化说明符 %5.0f
和一个文字 .
。这两部分没有任何连接。
第一部分打印出4个空格,然后是数字 2
,而第二部分只是独立地打印出 .
。
英文:
In the format string "%5.0f."
there are two parts: a floating point specifier %5.0f
and a literal .
. The two are not attached in any way.
The first part prints 4 spaces followed by the number 2
, and the second part just prints .
independently of the first part.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论