我正在学习更多的
PHP教程,特别是
DevZone PHP 101,我很困惑:
echo .sprintf("%4.2f", (2 * $radius * pi()))
我找到了这个
I think that means produce a floating-point field four positions wide with two decimal places, using the value of the first succeeding parameter.
That comes from the C/C++ line of programming languages. an sprintf() takes the first parameter as a format statement. Anything in it starting with a % is a field specifier; anything else is just printable text. So if you give a format statement with all text and no specifiers, it will print exactly the way it appears. With format specifiers, it needs data to work on.
但在尝试了一些不同的价值后,我仍然没有得到它.在我看来,如果在这种情况下它的目的只是将小数限制为2个位置,我必须放置
.sprintf("%.2f", (2 * $radius * pi()))
前面的4点有什么意义?在PHP Manual中,它让我相信它确定字符的总数应该是4但是(a)不是这种情况,因为小数点使它成为5个字符,而(b)不是这种情况,因为我尝试将其更改为更大像%8.2f这样的数字并没有在两端都添加任何零.有人可以更好地解释一下.
谢谢!