kchong Hoh
kchong Hoh

Reputation: 31

A very small exponential number in php

I have a very small exponential number and it display like:

5.2255534523412e-7

Can I display it become:

5.22e-7

Upvotes: 1

Views: 76

Answers (1)

Use sprintf() to format the output

http://php.net/sprintf

$a = 5.2255534523412e-7;

// change 2 to be how many decimal places you want. The e treats it as scientific notation.
echo sprintf('%.2e', $a);

Upvotes: 1

Related Questions