Unsparing
Unsparing

Reputation: 7653

PHP: Small Floating numbers are converted in scientific notation (E)

I have switched to ios and I have a weird problem when the server is displaying small numbers with precision points. So the following number for example:

0.000036

is represented like this when I var_dump it:

3.6E-5

How can I turn off this cause it's confusing to work in this notation?

Update:

I know with number_format I can display the number but in Windows there was no need... Is this some IOS settings that is doing it and can it be turned off?

Upvotes: 0

Views: 798

Answers (2)

Sarpyjr
Sarpyjr

Reputation: 177

number_format()

<?php
$num = 0.000036;
echo number_format($num,6);
?>

or, no matter how long the number is it would do it automatically for you

<?php
$num = 0.000036;
$length = strlen($num);
echo number_format($num,$length -1);
?>

Upvotes: 1

e_i_pi
e_i_pi

Reputation: 4820

If you are var_dumping the variable, you can use printf() to get it in the format you want without having to stipulate the decimal places you want it to:

  $var = 0.000036;
  var_dump(printf('%f', $var));

Upvotes: 0

Related Questions