diff --git a/doc/conf/LSattribute/LSattr_html/LSattr_html_valueWithUnit.docbook b/doc/conf/LSattribute/LSattr_html/LSattr_html_valueWithUnit.docbook
index bf565d3f..d3765129 100644
--- a/doc/conf/LSattribute/LSattr_html/LSattr_html_valueWithUnit.docbook
+++ b/doc/conf/LSattribute/LSattr_html/LSattr_html_valueWithUnit.docbook
@@ -10,7 +10,10 @@
'[facteur1]' => '[label unit1]',
'[facteur2]' => '[label unit2]',
[...]
- )
+ ),
+ 'nb_decimals' => [number of decimals],
+ 'dec_point' => '[decimals point]',
+ 'thousands_sep' => '[thousands separator]'
)
),]]>
...
@@ -26,6 +29,27 @@
+
+ nb_decimals
+
+ Le nombre de décimals à afficher en cas de nombre non-entier (Par defaut : 2).
+
+
+
+
+ dec_point
+
+ Le caractère à utiliser comme séparateur de décimal (Par defaut, une virgule).
+
+
+
+
+ thousands_sep
+
+ Le caractère à utiliser comme séparateur de milliers (Par defaut, un espace).
+
+
+
diff --git a/public_html/includes/class/class.LSformElement_valueWithUnit.php b/public_html/includes/class/class.LSformElement_valueWithUnit.php
index 71bba0ca..caa6f94d 100644
--- a/public_html/includes/class/class.LSformElement_valueWithUnit.php
+++ b/public_html/includes/class/class.LSformElement_valueWithUnit.php
@@ -53,6 +53,25 @@ class LSformElement_valueWithUnit extends LSformElement {
return;
}
+ /**
+ * Return formatted number
+ *
+ * This method return take a number as paremeter and
+ * return it after formatting.
+ *
+ * @param[in] int|float $number The number
+ *
+ * @retbal string Formatted number
+ */
+ function formatNumber($number) {
+ if ((int)$number==$number) return $number;
+ return number_format($number,
+ (isset($this -> params['html_options']['nb_decimals'])?$this -> params['html_options']['nb_decimals']:2),
+ (isset($this -> params['html_options']['dec_point'])?$this -> params['html_options']['dec_point']:","),
+ (isset($this -> params['html_options']['thousands_sep'])?$this -> params['html_options']['thousands_sep']:" ")
+ );
+ }
+
/**
* Retourne les infos d'affichage de l'élément
*
@@ -74,12 +93,10 @@ class LSformElement_valueWithUnit extends LSformElement {
);
foreach($units as $sill => $label) {
if ($infos['value'] >= $sill) {
- if ($infos['value'] % $sill == 0) {
- $infos['valueWithUnit']=$infos['value']/$sill;
- $infos['unitSill']=$sill;
- $infos['unitLabel']=$label;
- break;
- }
+ $infos['valueWithUnit']=$this -> formatNumber($infos['value']/$sill);
+ $infos['unitSill']=$sill;
+ $infos['unitLabel']=$label;
+ break;
}
}
$values_and_units[$value] = $infos;