Subversion Repositories Applications.gtt

Rev

Rev 139 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
139 jpm 1
<?php
2
 
3
class Nombre {
4
 
5
    public static function formaterNbre($tableau, $format = 'fr', $debog = false) {
6
		if (is_array($tableau)) {
7
			if ($debog) {
8
				trigger_error('pt2='.print_r($tableau, true), E_USER_NOTICE);
9
			}
10
			foreach ($tableau as $c => $v) {
11
				$tableau[$c] = Nombre::formaterNbre($v, $format, $debog);
12
				if ($debog) {
13
					trigger_error('pt3='.print_r($tableau[$c], true), E_USER_NOTICE);
14
				}
15
			}
16
		} else if (is_float($tableau) || is_int($tableau) || preg_match('/^(?:\d+|\d+\.\d+)$/', $tableau)) {
17
			if ($debog) {
18
				trigger_error('pt1='.print_r($tableau, true), E_USER_NOTICE);
19
			}
20
			switch ($format) {
21
				case 'fr' :
22
					if (is_float($tableau) || preg_match('/^\d+\.\d+$/', $tableau)) {
23
						// Nous supprimons les 0 après la virgule puis la virgule s'il n'y pas de chifre après
24
						$tableau = rtrim(rtrim(number_format($tableau, 2, ',', ' '), '0'), ',');
25
					}
26
					if (is_int($tableau) || preg_match('/^\d+$/', $tableau)) {
27
						$tableau = number_format($tableau, 0, ',', ' ');
28
					}
29
					break;
30
				default:
31
					trigger_error("Format pour les nombres non pris en charge : $format", E_USER_WARNING);
32
			}
33
		}
34
		return $tableau;
35
    }
36
}
37
?>