Формат вывода float чисел.

  • Автор темы Автор темы Norton
  • Дата начала Дата начала

Norton

Новичок
Формат вывода float чисел.

Подскажите как вывести на екран число float
с E точностью ?

В Си так
float f=00.222;
printf("%.e",f);

А PHP такое не работает. :(
А как это сделать правильно ?
 
Нашел в описании sprintf:

The 'e' format specifier is not documented. However, it seems to work, but without showing the exponential part of the number.
This is a function to get the scientific representation of a number:
function sci($x, $d=-1) {
$e=floor(log10($x));
$x*=pow(10,-$e);
$fmt=($d>=0)?".".$d:"";
$e=($e>=0)?"+".sprintf("%02d",$e):"-".sprintf("%02d",-$e);
return sprintf("%".$fmt."fe%s",$x,$e);
}
It takes the number as the first parameter and the precision as the second. The precision is optional. The default precision for the 'f' format specifier is used if no precision is specified.

Вот таким образом все и заработало.
 
Сверху