Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is PHP printing my number in scientific notation, when I specified it as .000021?

In PHP I have the following code:

<?PHP   $var = .000021;   echo $var; ?> 

the output is 2.1E-5 !

Why? it should print .000021

like image 629
ahmed Avatar asked Sep 24 '09 13:09

ahmed


People also ask

How do you get rid of scientific notation in numbers?

(1) Right-click a cell where you want to remove scientific notation, and (2) choose Format Cells… 2. In the Format Cells window, (1) select the Number category, (2) set the number of decimal places to 0, and (3) click OK. Now the scientific notation is removed.

How do you stop scientific notation when printing float values?

There is a simple technique to suppress scientific notation when using float values by using the %f flag in string. This will convert the number into a floating-point number and then print it.


1 Answers

Use number_format() to get what you're after:

print number_format($var, 5); 

Also check sprintf()

like image 63
acrosman Avatar answered Oct 23 '22 13:10

acrosman