gpt4 book ai didi

php - PHP 中的 sprintf 长度说明符

转载 作者:行者123 更新时间:2023-12-02 03:01:00 26 4
gpt4 key购买 nike

包含 length specifier 有什么好处吗?格式字符串为 sprintfprintf即使没有提到in the PHP manual :

  • h - 参数被解释为短整型或无符号短整型(仅适用于整数说明符: idouxX )。
  • l - 对于整数说明符( idouxX ),参数被解释为 long int 或 unsigned long int,以及宽字符或宽字符说明符字符串 cs .
  • L - 参数被解释为 long double (仅适用于浮点说明符: eEfgG )。

还是把它去掉更好?我想我想弄清楚为什么 php 决定将其排除在外。

考虑以下来自 phpriot.com 的代码:

$a = 0.5;
$b = 0.1;
$c = 16;

echo sprintf('%01.2lf %.1lf 0x%x', $a, $b, $c); # 0.50 0.1 0x10

最佳答案

在 PHP 中,除了 Integers 之外,数字之间没有区别。和 Floats 。根据系统架构(32 位或 64 位),Integer 类型为 int 或 int64。您可以使用字符串和 BCMath 来模拟更大的数字,但它们将始终存储在字符串中。

因此,在 PHP 中,没有必要使用长度说明符来更改数字的类型。它要么是 float 的,要么不是。

关于php - PHP 中的 sprintf 长度说明符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11212215/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com