New file |
0,0 → 1,37 |
<?php |
|
class Nombre { |
|
public static function formaterNbre($tableau, $format = 'fr', $debog = false) { |
if (is_array($tableau)) { |
if ($debog) { |
trigger_error('pt2='.print_r($tableau, true), E_USER_NOTICE); |
} |
foreach ($tableau as $c => $v) { |
$tableau[$c] = Nombre::formaterNbre($v, $format, $debog); |
if ($debog) { |
trigger_error('pt3='.print_r($tableau[$c], true), E_USER_NOTICE); |
} |
} |
} else if (is_float($tableau) || is_int($tableau) || preg_match('/^(?:\d+|\d+\.\d+)$/', $tableau)) { |
if ($debog) { |
trigger_error('pt1='.print_r($tableau, true), E_USER_NOTICE); |
} |
switch ($format) { |
case 'fr' : |
if (is_float($tableau) || preg_match('/^\d+\.\d+$/', $tableau)) { |
// Nous supprimons les 0 après la virgule puis la virgule s'il n'y pas de chifre après |
$tableau = rtrim(rtrim(number_format($tableau, 2, ',', ' '), '0'), ','); |
} |
if (is_int($tableau) || preg_match('/^\d+$/', $tableau)) { |
$tableau = number_format($tableau, 0, ',', ' '); |
} |
break; |
default: |
trigger_error("Format pour les nombres non pris en charge : $format", E_USER_WARNING); |
} |
} |
return $tableau; |
} |
} |
?> |