0

何もしないベンチマーク テストを実行しているので、結果はかなり高速です。

これが私のコードです:

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

echo 'Took '.$time.' seconds<br>';

問題は、私がこれを得ている結果をエコーし​​ようとするときです:

Took 1.3828277587891E-5 seconds

次のような通常の10進数を取得することを期待しています:

Took 0.000000008231 seconds

PHPに通常の10進数として表示させることはできますか?

4

3 に答える 3

1

printfまたはsprintf関数を使用できます。これはhttp://php.net/manual/en/function.sprintf.phpのサンプルです

<?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

あなたの例では、 -for instance- を使用できます:

<?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
于 2015-01-13T00:15:55.407 に答える