round

Snippet: function round_e()

I recently helped a poster at HTML Forums who wanted to be able to reformat floating point numbers in PHP.

The problem is that some of these numbers were in exponential format. There was also a requirement not to round a number like 0.004 to 0, although the 'precision' was to be constant for all uses of this function in the script.

8.8458e-119    = 8.84e-119
1.06542e-52    = 1.07e-52
2.68e-36       = 2.68e-36
2.91405e-35    = 2.92e-35
0.0190644      = 0.01
0.0205511      = 0.02
0.004          = 0.004