Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 强制显示常规十进制数_Php_Time_Numbers_Decimal_Microtime - Fatal编程技术网

Php 强制显示常规十进制数

Php 强制显示常规十进制数,php,time,numbers,decimal,microtime,Php,Time,Numbers,Decimal,Microtime,我正在运行一个什么都不做的基准测试,所以结果非常快 这是我的密码: $time_start = microtime(true); //Do Nothing... $time = microtime(true) - $time_start; echo 'Took '.$time.' seconds<br>'; 我希望得到一个常规的十进制数,如: Took 0.000000008231 seconds 是否可以强制php将其显示为常规十进制数?如果您想要大数字,请尝试以下操作:

我正在运行一个什么都不做的基准测试,所以结果非常快

这是我的密码:

$time_start = microtime(true);
//Do Nothing...
$time = microtime(true) - $time_start;

echo 'Took '.$time.' seconds<br>';
我希望得到一个常规的十进制数,如:

Took 0.000000008231 seconds

是否可以强制php将其显示为常规十进制数?

如果您想要大数字,请尝试以下操作:

  //$i = gmp_init( $time ); // i think you need that only if you want convert a string to an int/flaot
  echo gmp_strval( $time );
gmp_标准PHP>4.0.4/PHP 5


Mor infos

您可以使用
printf
sprintf
功能。这是我的一个样品

您可以使用number_格式()
检查

PHP将根据ini文件中的精度设置切换到使用科学格式:I修改该设置,或使用强制非科学格式显示类似问题的可能副本,并给出正确答案:是的,我在那篇文章中得到了答案!谢谢看起来很有趣,但是。。。致命错误:在…中调用未定义的函数gmp_init()。我假设这是我的PHP版本,但我将在更高版本上测试它…:)回答接受!这正是我要找的!
  //$i = gmp_init( $time ); // i think you need that only if you want convert a string to an int/flaot
  echo gmp_strval( $time );
<?php
$n =  43951789;
$u = -43951789;
$c = 65; // ASCII 65 is 'A'

// notice the double %%, this prints a literal '%' character
printf("%%b = '%b'\n", $n); // binary representation
printf("%%c = '%c'\n", $c); // print the ascii character, same as chr() function
printf("%%d = '%d'\n", $n); // standard integer representation
printf("%%e = '%e'\n", $n); // scientific notation
printf("%%u = '%u'\n", $n); // unsigned integer representation of a positive integer
printf("%%u = '%u'\n", $u); // unsigned integer representation of a negative integer
printf("%%f = '%f'\n", $n); // floating point representation
printf("%%o = '%o'\n", $n); // octal representation
printf("%%s = '%s'\n", $n); // string representation
printf("%%x = '%x'\n", $n); // hexadecimal representation (lower-case)
printf("%%X = '%X'\n", $n); // hexadecimal representation (upper-case)

printf("%%+d = '%+d'\n", $n); // sign specifier on a positive integer
printf("%%+d = '%+d'\n", $u); // sign specifier on a negative integer
<?php
$time_start = microtime(true);
//Do Nothing...
$time = microtime(true) - $time_start;

echo 'Took '.sprintf("%f",$time).' seconds<br>';
sprintf("%.1f",$time) // -> 0.0 seconds

sprintf("%.10f",$time) // -> 0.0000059605 seconds