Принудительно отображать обычное десятичное число

Я провожу контрольный тест, ничего не делая, поэтому результаты довольно быстрые.

Вот мой код:

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

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

Проблема в том, что когда я пытаюсь повторить результаты, я получаю это:

Took 1.3828277587891E-5 seconds

Я ожидаю получить обычное десятичное число, например:

Took 0.000000008231 seconds

Можно ли заставить php отображать его как обычное десятичное число?

0

Решение

Если вы хотите ваши большие цифры, попробуйте это:

  //$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_strval PHP> 4.0.4 / PHP 5.

Мор информация http://php.net/manual/en/function.gmp-strval.php

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
1

Вы можете использовать number_format ()
Проверьте http://php.net/number_format

0
По вопросам рекламы ammmcru@yandex.ru
Adblock
detector