6
votes

Ajouter un point décimal 2 caractères de droite sous PHP

J'ai un grand tableau contenant beaucoup d'éléments contenant des données numériques.

Exemple: p> xxx pré>

Je veux convertir ces en: p>

32.00
343.00
14.99
128.99


0 commentaires

3 Réponses :


0
votes

Utilisation de Number_Format . xxx


0 commentaires

18
votes
$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. 

1 commentaires

Utile pour API d'Amazon publicitaire API qui renvoie un objet où le prix est formaté sans aucun point décimal.



2
votes

ou, si vous aimez les fonctions anonymes et php 5.3: xxx

sortie: xxx

toujours et tout, la réponse est la solution Même: utilisez number_format () .


0 commentaires