mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2024-11-22 09:59:06 +01:00
LSformElement :: valueWithUnit : improve floatint number display and add parameter for formatting control
This commit is contained in:
parent
91dbcf4a6e
commit
dfafd88159
2 changed files with 48 additions and 7 deletions
|
@ -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 @@
|
|||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>nb_decimals</term>
|
||||
<listitem>
|
||||
<simpara>Le nombre de décimals à afficher en cas de nombre non-entier (Par defaut : <literal>2</literal>).</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>dec_point</term>
|
||||
<listitem>
|
||||
<simpara>Le caractère à utiliser comme séparateur de décimal (Par defaut, une virgule).</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>thousands_sep</term>
|
||||
<listitem>
|
||||
<simpara>Le caractère à utiliser comme séparateur de milliers (Par defaut, un espace).</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
</variablelist>
|
||||
|
||||
</sect4>
|
||||
|
|
|
@ -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,14 +93,12 @@ 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['valueWithUnit']=$this -> formatNumber($infos['value']/$sill);
|
||||
$infos['unitSill']=$sill;
|
||||
$infos['unitLabel']=$label;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$values_and_units[$value] = $infos;
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Reference in a new issue