matlab中 4.2f,.sprintf(“%4.2f”,value)如何在PHP中运行?

我正在学习更多的

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这样的数字并没有在两端都添加任何零.有人可以更好地解释一下.

谢谢!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值