Code comment
This commit is contained in:
parent
f11a85a3e3
commit
5f8b52ffc9
@ -5159,7 +5159,7 @@ function price2num($amount, $rounding = '', $option = 0)
|
||||
|
||||
// Convert value to universal number format (no thousand separator, '.' as decimal separator)
|
||||
if ($option != 1) { // If not a PHP number or unknown, we change or clean format
|
||||
//print 'PP'.$amount.' - '.$dec.' - '.$thousand.' - '.intval($amount).'<br>';
|
||||
//print "\n".'PP'.$amount.' - '.$dec.' - '.$thousand.' - '.intval($amount).'<br>';
|
||||
if (!is_numeric($amount)) {
|
||||
$amount = preg_replace('/[a-zA-Z\/\\\*\(\)\<\>\_]/', '', $amount);
|
||||
}
|
||||
@ -5188,6 +5188,7 @@ function price2num($amount, $rounding = '', $option = 0)
|
||||
$amount = str_replace($thousand, '', $amount); // Replace of thousand before replace of dec to avoid pb if thousand is .
|
||||
$amount = str_replace($dec, '.', $amount);
|
||||
}
|
||||
//print ' XX'.$amount.' '.$rounding;
|
||||
|
||||
// Now, make a rounding if required
|
||||
if ($rounding) {
|
||||
@ -5205,13 +5206,13 @@ function price2num($amount, $rounding = '', $option = 0)
|
||||
} elseif (is_numeric($rounding)) {
|
||||
$nbofdectoround = (int) $rounding;
|
||||
}
|
||||
//print "RR".$amount.' - '.$nbofdectoround.'<br>';
|
||||
//print " RR".$amount.' - '.$nbofdectoround.'<br>';
|
||||
if (dol_strlen($nbofdectoround)) {
|
||||
$amount = round(is_string($amount) ? (float) $amount : $amount, $nbofdectoround); // $nbofdectoround can be 0.
|
||||
} else {
|
||||
return 'ErrorBadParameterProvidedToFunction';
|
||||
}
|
||||
//print 'SS'.$amount.' - '.$nbofdec.' - '.$dec.' - '.$thousand.' - '.$nbofdectoround.'<br>';
|
||||
//print ' SS'.$amount.' - '.$nbofdec.' - '.$dec.' - '.$thousand.' - '.$nbofdectoround.'<br>';
|
||||
|
||||
// Convert amount to format with dolibarr dec and thousand (this is because PHP convert a number
|
||||
// to format defined by LC_NUMERIC after a calculation and we want source format to be defined by Dolibarr setup.
|
||||
|
||||
@ -108,7 +108,15 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase
|
||||
//$db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
|
||||
|
||||
if (! function_exists('mb_substr')) {
|
||||
print "\n".__METHOD__." function mb_substr must be enabled.\n"; die();
|
||||
print "\n".__METHOD__." function mb_substr must be enabled.\n"; die(1);
|
||||
}
|
||||
|
||||
if ($conf->global->MAIN_MAX_DECIMALS_UNIT != 5) {
|
||||
print "\n".__METHOD__." bad setup for number of digits for unit amount. Must be 5 for this test.\n"; die(1);
|
||||
}
|
||||
|
||||
if ($conf->global->MAIN_MAX_DECIMALS_TOT != 2) {
|
||||
print "\n".__METHOD__." bad setup for number of digits for unit amount. Must be 2 for this test.\n"; die(1);
|
||||
}
|
||||
|
||||
print __METHOD__."\n";
|
||||
@ -1294,7 +1302,7 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase
|
||||
$this->assertEquals(1000.123456, price2num('1 000.123456'));
|
||||
|
||||
// Round down
|
||||
$this->assertEquals(1000.12, price2num('1 000.123452', 'MT'));
|
||||
$this->assertEquals(1000.12, price2num('1 000.123452', 'MT'), 'Error in round down with MT');
|
||||
$this->assertEquals(1000.12345, price2num('1 000.123452', 'MU'), "Test MU");
|
||||
|
||||
// Round up
|
||||
|
||||
Loading…
Reference in New Issue
Block a user