Fix: Pb in float number with non fr languages

This commit is contained in:
Laurent Destailleur
2008-08-17 21:13:21 +00:00
parent ff5ac3e919
commit 5ffa63426c
4 changed files with 38 additions and 16 deletions

View File

@@ -65,6 +65,15 @@ $var=!$var;
print "<tr ".$bc[$var]."><td width=\"300\">".$langs->trans("LanguageParameter","PHP LC_TIME")."</td><td>".setlocale(LC_TIME,0)."</td></tr>\n";
$var=!$var;
print "<tr ".$bc[$var]."><td width=\"300\">".$langs->trans("LanguageParameter","PHP LC_MONETARY")."</td><td>".setlocale(LC_MONETARY,0)."</td></tr>\n";
// Decimals
$var=!$var;
$dec=$langs->trans("SeparatorDecimal");
print "<tr ".$bc[$var]."><td width=\"300\">".$langs->trans("CurrentValueSeparatorDecimal")."</td><td>".$dec."</td></tr>\n";
$var=!$var;
$thousand=$langs->trans("SeparatorThousand");
if ($thousand == 'SeparatorThousand') $thousand=' '; // ' ' does not work on trans method
print "<tr ".$bc[$var]."><td width=\"300\">".$langs->trans("CurrentValueSeparatorThousand")."</td><td>".$thousand."</td></tr>\n";
// Timezone
$var=!$var;
print "<tr ".$bc[$var]."><td width=\"300\">".$langs->trans("DolibarrTZ")."</td><td>".$langs->trans("FeatureNotYetAvailable")."</td></tr>\n";
$var=!$var;

View File

@@ -59,6 +59,8 @@ Active=Active
SetupShort=Setup
OtherOptions=Other options
OtherSetup=Other setup
CurrentValueSeparatorDecimal=Decimal separator
CurrentValueSeparatorThousand=Thousand separator
Modules=Modules
ModulesCommon=Common modules
ModulesInterfaces=Interfaces modules
@@ -69,7 +71,7 @@ ParameterInDolibarr=Parameter %s
LanguageParameter=Language parameter %s
LanguageBrowserParameter=Parameter %s
LocalisationDolibarrParameters=Localisation parameters
DolibarrTZ=Time Zone
DolibarrTZ=Time Zone Dolibarr
ServerTZ=Time Zone Server
PHPTZ=Time Zone PHP
PHPServerOffsetWithGreenwich=Offset for PHP server width Greenwich (secondes)

View File

@@ -59,6 +59,8 @@ Active=Actif
SetupShort=Config
OtherOptions=Autres options
OtherSetup=Divers
CurrentValueSeparatorDecimal=S<>parateur d<>cimal
CurrentValueSeparatorThousand=S<>parateur de milliers
Modules=Modules
ModulesCommon=Modules standards
ModulesInterfaces=Modules interfaces
@@ -69,7 +71,7 @@ ParameterInDolibarr=Variable %s
LanguageParameter=Variable langue %s
LanguageBrowserParameter=Variable %s
LocalisationDolibarrParameters=Param<61>tres de localisation
DolibarrTZ=Time Zone
DolibarrTZ=Time Zone Dolibarr
ServerTZ=Time Zone Serveur
PHPTZ=Time Zone PHP
PHPServerOffsetWithGreenwich=Offset serveur PHP avec Greenwich (secondes)

View File

@@ -1963,14 +1963,14 @@ function vatrate($rate,$addpercent=false,$info_bits=0)
* \param trunc 1=Tronque affichage si trop de decimales,0=Force le non troncage
* \param nbdecimal Nbre decimals minimum.
* \return string Chaine avec montant formate
* \seealso price2num Fonction inverse de price
* \seealso price2num Revert function of price
*/
function price($amount, $html=0, $outlangs='', $trunc=1, $nbdecimal=2)
{
global $langs,$conf;
// Separateurs par defaut
$dec='.'; $thousand=' ';
// Output separators by default (french)
$dec=','; $thousand=' ';
// Si $outlangs non force, on prend langue utilisateur
if (! is_object($outlangs)) $outlangs=$langs;
@@ -1980,15 +1980,15 @@ function price($amount, $html=0, $outlangs='', $trunc=1, $nbdecimal=2)
//print "amount=".$amount." html=".$html." trunc=".$trunc." nbdecimal=".$nbdecimal." dec=".$dec." thousand=".$thousand;
//print "amount=".$amount."-";
$amount = ereg_replace(',','.',$amount);
$amount = ereg_replace(',','.',$amount); // should be useless
//print $amount."-";
$datas = split('\.',$amount);
$decpart = $datas[1];
$decpart = eregi_replace('0+$','',$decpart); // Supprime les 0 de fin de partie d<EFBFBD>cimale
$decpart = eregi_replace('0+$','',$decpart); // Supprime les 0 de fin de partie decimale
//print "decpart=".$decpart."<br>";
$end='';
// On augmente au besoin si il y a plus de 2 d<>cimales
// On augmente nbdecimal au besoin si il y a plus de decimales que nbdecimal
if (strlen($decpart) > $nbdecimal) $nbdecimal=strlen($decpart);
// Si on depasse max
if ($trunc && $nbdecimal > $conf->global->MAIN_MAX_DECIMALS_SHOWN)
@@ -1996,7 +1996,7 @@ function price($amount, $html=0, $outlangs='', $trunc=1, $nbdecimal=2)
$nbdecimal=$conf->global->MAIN_MAX_DECIMALS_SHOWN;
if (eregi('\.\.\.',$conf->global->MAIN_MAX_DECIMALS_SHOWN))
{
// Si un affichage est tronqu<EFBFBD>, on montre des ...
// Si un affichage est tronque, on montre des ...
$end='...';
}
}
@@ -2029,21 +2029,30 @@ function price($amount, $html=0, $outlangs='', $trunc=1, $nbdecimal=2)
*/
function price2num($amount,$rounding='')
{
global $conf;
global $langs,$conf;
// Round PHP function does not allow number like '1,234.5'.
// Round PHP function does not allow number like '1,234.5'
// Numbers must be '1234.5'
// \TODO If there is already a ".", we remove ",", otherwise replace by "."
$amount=ereg_replace(',','.',$amount);
$amount=ereg_replace(' ','',$amount);
// Decimal delimiter for database SQL request must be '.'
$dec=','; $thousand=' ';
if ($langs->trans("SeparatorDecimal") != "SeparatorDecimal") $dec=$langs->trans("SeparatorDecimal");
if ($langs->trans("SeparatorThousand")!= "SeparatorThousand") $thousand=$langs->trans("SeparatorThousand");
if ($thousand != ',') $amount=str_replace(',','.',$amount); // To accept 2 notations for french users
$amount=str_replace(' ','',$amount); // To avoid spaces
$amount=str_replace($dec,'.',$amount);
$amount=str_replace($thousand,'',$amount);
if ($rounding)
{
if ($rounding == 'MU') $amount = round($amount,$conf->global->MAIN_MAX_DECIMALS_UNIT);
elseif ($rounding == 'MT') $amount = round($amount,$conf->global->MAIN_MAX_DECIMALS_TOT);
elseif ($rounding == 'MS') $amount = round($amount,$conf->global->MAIN_MAX_DECIMALS_SHOWN);
else $amount='ErrorBadParameterProvidedToFunction';
$amount=ereg_replace(',','.',$amount);
$amount=ereg_replace(' ','',$amount);
if ($thousand != ',') $amount=str_replace(',','.',$amount); // To accept 2 notations for french users
$amount=str_replace(' ','',$amount); // To avoid spaces
$amount=str_replace($dec,'.',$amount);
$amount=str_replace($thousand,'',$amount);
}
return $amount;
}