tags:

views:

68

answers:

3

I have a big array containing lots of elements containing numerical data.

Example:

3200
34300
1499
12899

I want to convert these into:

32.00
343.00
14.99
128.99

How can I achieve this elegantly under PHP using no regex?

Thanks in advance.

A: 

Using number_format.

for($i=0;$i<count($array);$i++)
{
    $array[$i] = number_format($array[$i]/100,2);
    //if you need them as numbers
    $array[$i] = (float) number_format($array[$i]/100,2);
}
Alan Storm
+3  A: 
$new_array=array();
foreach($old_array as $value)
{
   $new_array[]=number_format(($value/100),2);
}

See number_format if you want to fiddle with the thousands separator or something. See foreach if you want to modify the array values in place.

ansate
Works, thank you.
google
+2  A: 
hlpiii