nixnub
nixnub

Reputation: 669

In php, when working with very small numbers, how can i see the exact number, and not "2.1934509277344E-5"?

I am working with microtime() to time some scripts, but all the scripts have really quick times, eg 2.1934509277344E-5

how can i get php to display that correctly without e-5?

(which i assume is 0.000021934509277344? long time since i did maths...)

Upvotes: 0

Views: 1117

Answers (2)

NawaMan
NawaMan

Reputation: 25677

Try this: trim(sprintf('%40.20f', 2.1934509277344E-5)). %40.20f tells sprintf to display 40 digit with 20 digit of decimal. You can adjust this as you wish. The number will be space-led to fill 40 digits so I trim it.

Hope this helps.

Upvotes: 0

nickf
nickf

Reputation: 546303

You can use (s)printf

$myVal = 0.0000002;
echo $myVal;   // "2.0E-7"
printf("%0.7f", $myVal);  // "0.0000002"

Upvotes: 6

Related Questions