Posted on 2007-07-23
I am using a number which can have up to 8 decimal places. However this number is actually currency so i would like it to display clearly.
I need to make sure i have no less than 2 decimal places but display anywhere up to 8.
For example i need these numbers to display these results:
0.2 = 0.20
0.1 = 0.1
0.15 = 0.15
0.156800 = 0.156800
0.268 = 0.268
1.95660010 = 1.9566001
I am currently using this code which works fine but it will not leave me with 2 decimal places if the last number is a 0.
$longDecimal = number_format($old_number, 8, '.', '');
$number = preg_replace('/\.?0+$/', '', $longDecimal);
Does anybody no the preg_replace pattern for only replacing chars after 2 decimal places??